Alex
Alex

Reputation: 67710

Magic for undefined function?

Is there such a thing?

Some kind of a magic function that allows you to change stuff before the undefined function call error gets thrown?

Like __call, but for normal functions :)

Upvotes: 4

Views: 818

Answers (1)

Mārtiņš Briedis
Mārtiņš Briedis

Reputation: 17762

I would do the cheking BEFORE calling the method like this:

$obj = new Foo();
$method = "myMethod";

if(is_callable(array($obj, $method)){
    $obj->$method();
}else{
    // Do some stuff
}

Upvotes: 2

Related Questions