note 103635 added to function.method-exists
| From: | mail at bartrail dot de | Date: | Mon, 25 Apr 2011 17:06:16 +0000 |
| Subject: | note 103635 added to function.method-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179121@lists.php.net to get a copy of this message | ||
Using method_exists inside an object's __call() method can be very usefull if you want to avoid
to get a fatal error because of a limit in function nesting or if you are calling methods that dont
exist but need to continue in your application:
<?php
class Something
{
/**
* Call a method dynamically
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if(method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $args);
}else{
throw new Exception(sprintf('The required method "%s" does not exist for
%s', $method, get_class($this)));
}
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 91.52.130.10
----
Manual Page -- http://www.php.net/manual/en/function.method-exists.php
Edit -- https://master.php.net/note/edit/103635
Del: integrated -- https://master.php.net/note/delete/103635/integrated
Del: useless -- https://master.php.net/note/delete/103635/useless
Del: bad code -- https://master.php.net/note/delete/103635/bad+code
Del: spam -- https://master.php.net/note/delete/103635/spam
Del: non-english -- https://master.php.net/note/delete/103635/non-english
Del: in docs -- https://master.php.net/note/delete/103635/in+docs
Del: other reasons-- https://master.php.net/note/delete/103635
Reject -- https://master.php.net/note/reject/103635
Search -- https://master.php.net/manage/user-notes.php