Search code examples
phpcalltraitsmagic-methods

Catch calling of the existing methods


I have a class, which involves traits:

class Dynamic
{
   use Trait1, Trait2;

   public function method3(){};
}

So I need, when i'm trying to use this class like

$obj = new Dynamic(); 
$obj->getName(); // method from the Trait1

get some notifications that methods from the trait were called.

Can you advice some method for this task?


Solution

  • This seems expected, no?

    __call() is triggered when invoking inaccessible methods in an object context.

    https://www.php.net/manual/en/language.oop5.overloading.php