- var_dump: documentation ( source)
- method_exists: documentation ( source)
<?php
class Foo
{
private $bar;
private $baz;
protected function getBar()
{
return __METHOD__;
}
private function getBaz()
{
return __METHOD__;
}
public function __call($methodName, $args)
{
if (!method_exists($this, $methodName)) {
return 'some wise behavior';
}
return 'Magic! '.$this->$methodName(...$args);
}
}
$foo = new Foo();
var_dump(method_exists($foo, '__call'));
var_dump(method_exists($foo, 'bar'));
var_dump(method_exists($foo, 'baz'));
var_dump($foo->__call('baz', []));
var_dump($foo->baz());
var_dump($foo->__call('nonexistent', []));