And you lost me
__call() allows you to catch calls to a non existing class method and reroute them, perhaps to a parent method or child property method
so if you called a non existent function from inside of __call() you would be calling the function recursively until the memory is exhausted (stack overflow)
Commonly, it would be used for uniting multiple objects under a common interface, to prevent scoping problems in a large project, but still separating concerns of each class/library.
Here's an example:
namespace App;
class App
{
private $slim; // slim is only accessible from \App\App
function __construct( $slim )
{
$this->slim = $slim;
}
// hmm, now i want to call a slim function but have no way to do so because slim is private
// __call() to the rescue!
public function __call($name, $args = false)
{
if(method_exists($this->slim,$name)){
if($args)
return call_user_func_array( [$this->slim,$name] , $args);
else
return call_user_func( [$this->slim,$name] );
}
// if we made it here, no method exists. lets call our logger function
$this->loggerr(); // notice the typo. infinite recursion results because you are recursively calling __call()
}
public function logger()
{
// something bad happened
throw new \exception('potato');
}
}