Reputation: 510
class Foo {
private $_bar;
public function getBar() {
return $this->_bar;
}
}
$b = new Foo();
$b->xxx(); //xxx is an udefined method.
How to enhance the following class to throw a notice if undefined methods is called?
Upvotes: 0
Views: 75
Reputation: 21856
class Foo {
private $_bar;
public function getBar() {
return $this->_bar;
}
public function __call($name, $params)
{
throw new Exception("Method $name does not exists!");
}
}
Upvotes: 3
Reputation: 54016
write __call in Class Foo
function __call( $functionName, $argumentsArray ) {
echo "Function $functionName does not exist";
}
Upvotes: 0
Reputation: 364
You have to define a the __call( $methodName , $args ) method.
And throw your own exception from there.
Upvotes: 3
Reputation: 174957
A PHP warning would be thrown like any other time when you call an undefined function. You need to enable it with error_reporting(E_ALL);
.
Upvotes: 0