note 27839 added to functions.variable-functions

From: Date: Fri, 20 Dec 2002 13:33:25 +0000
Subject: note 27839 added to functions.variable-functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-41153@lists.php.net to get a copy of this message
A good method to pass around variables containing function names within some class is to use the same method as the developers use in preg_replace_callback - with arrays containing an instance of the class and the function name itself. function call_within_an_object($fun) { if(is_array($fun)) { /* call a function within an object */ $fun[0]->{$fun[1]}(); } else { /* call some other function */ $fun(); } } function some_other_fun() { /* code */ } class x { function fun($value) { /* some code */ } } $x = new x(); /* the following line calls $x->fun() */ call_within_an_object(Array($x, 'fun')); /* the following line calls some_other_fun() */ call_within_an_object('some_other_fun'); -- http://www.php.net/manual/en/functions.variable-functions.php http://master.php.net/manage/user-notes.php?action=edit+27839 http://master.php.net/manage/user-notes.php?action=delete+27839 http://master.php.net/manage/user-notes.php?action=reject+27839

« previous php.notes (#41153) next »