note 78159 added to ref.overload
| From: | none at example dot com | Date: | Mon, 01 Oct 2007 10:42:37 +0000 |
| Subject: | note 78159 added to ref.overload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130957@lists.php.net to get a copy of this message | ||
I am coding a server with a lot of method. To avoid doing a $this->check_auth() call (and others
similar processing) in _each_ on my method, I was looking for a way to wrap them all through a
dispatch.
Combining _call, with call_user_func_array is the way I did it finally.
So basically, if you want to call "testFunc" you just call $class->test () and
it will be wrapped and testFunc will be executed.
<?php
class MytestClass
{
function __call($method, $param)
{
// do anything here
return (call_user_func_array (array ("MytestClass", $method."Func"),
$param));
}
function testFunc($param, $arg)
{
echo "It works ! Param: $param, ARG=$arg\n";
return true;
}
}
$test = new MytestClass;
$test->test ("Cool", "Test");
?>
----
Server IP: 69.147.83.197
Probable Submitter: 82.67.176.238
----
Manual Page -- http://www.php.net/manual/en/ref.overload.php
Edit -- https://master.php.net/note/edit/78159
Del: integrated -- https://master.php.net/note/delete/78159/integrated
Del: useless -- https://master.php.net/note/delete/78159/useless
Del: bad code -- https://master.php.net/note/delete/78159/bad+code
Del: spam -- https://master.php.net/note/delete/78159/spam
Del: non-english -- https://master.php.net/note/delete/78159/non-english
Del: in docs -- https://master.php.net/note/delete/78159/in+docs
Del: other reasons-- https://master.php.net/note/delete/78159
Reject -- https://master.php.net/note/reject/78159
Search -- https://master.php.net/manage/user-notes.php