note 25946 deleted from function.eval by irchtml
| From: | irchtml@php.net | Date: | Tue, 17 Feb 2004 14:29:10 +0000 |
| Subject: | note 25946 deleted from function.eval by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65297@lists.php.net to get a copy of this message | ||
Note Submitter: mjohnson@onfiber.com
----
If anyone was interested, I figured out how to store and call member functions. There might be a
better, more PHP way of doing it but I couldn't find anything on the web or in the newsgroups.
If you ever wanted to try to implement a Command Pattern or Factory Pattern you can use the
technique below:
class Processor {
var $_callbacks;
function Processor( $cmd )
{
$this->_callbacks = array( "add"=>"add()"
, "cha"=>"change()"
, "del"=>"delete()"
, "new"=>"add()"
, "mod"=>"change()"
, "rem"=>"delete()"
);
$proc = $this->_callbacks[$cmd];
if( $proc )
eval( '$this->'."$proc;" );
}
function add() { echo "add"; }
function change() { echo "change"; }
function delete() { echo "delete"; }
}