Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 350 Bytes

call_trait_method_with_our_custom_name.md

File metadata and controls

21 lines (18 loc) · 350 Bytes

Call trait method with our custom name

We can call any trait method inside our class with the name we have provided

trait MyTrait
{
    public function foo()
    {
        var_dump('Hello from trait.');
    }
}

class SomeClass
{
    use MyTrait {
        foo as anotherFoo;
    }
}

(new SomeClass)->anotherFoo(); // Hello from trait.