__call for existing methods?
| From: | Maximiliano Churichi | Date: | Fri, 21 May 2010 18:46:49 +0000 |
| Subject: | __call for existing methods? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-305402@lists.php.net to get a copy of this message | ||
Is there a way to catch EVERY method of a inheritance class?
something like this...
class Father
{
public function __call ($name, $args)
{
$this->doSomethingBefore();
if ( method_exists($this, $name) )
return $this->$name($args);
else
echo 'invalid method';
}
public function doSomethingBefore ()
{
echo 'something before called method';
}
}
class Son extends Father
{
public function insert ()
{
echo 'inserting';
}
}
$johnDoe = new Son();
$johnDoe->insert();
/*
-- Expected return:
something before called method
inserting
*/
$johnDoe->foo();
/*
-- Expected return:
something before called method
invalid method
*/
Greetings...
--
Maximiliano Churichi
<mchurichi@gmail.com>