Be careful of __call in case you have a protected/private method. Doing this:
<?php
class TestMagicCallMethod {
public function foo()
{
echo __METHOD__.PHP_EOL;
}
public function __call($method, $args)
{
echo __METHOD__.PHP_EOL;
if(method_exists($this, $method))
{
$this->$method();
}
}
protected function bar()
{
echo __METHOD__.PHP_EOL;
}
private function baz()
{
echo __METHOD__.PHP_EOL;
}
}
$test = new TestMagicCallMethod();
$test->foo();
$test->bar();
$test->baz();
?>
..is probably not what you should be doing. Always make sure that the methods you call in __call are allowed as you probably dont want all the private/protected methods to be accessed by a typo or something.