Is there a magic method that when a certain method is called from an object, that a magic method is called first. Kinda like the __call method, but this only gets triggered when the method isn’t found.
So in my case i’d like something like this:
class MyClass
{
public function __startMethod ( $method, $args )
{
// a method just got called, so this is called first
echo ' [start] ';
}
public function helloWorld ( )
{
echo ' [Hello] ';
}
}
$obj = new MyClass();
$obj->helloWorld();
//Output:
[start] [Hello]
Does something like this exist in PHP??
There isn’t a direct way to do this but it looks to me like your trying to implement a form of Aspect Oriented programming. There are several ways of achieving this in PHP, one would be to set up your class something like the following:
Look up other ways of implementing AOP in PHP to see what works best for you (I’ll see if I can find a link somewhere).
EDIT: here’s a document for you http://www.liacs.nl/assets/Bachelorscripties/07-MFAPouw.pdf