note 25946 added to function.eval

From: Date: Sat, 12 Oct 2002 03:18:41 +0000
Subject: note 25946 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-37967@lists.php.net to get a copy of this message
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"; } } -- http://www.php.net/manual/en/function.eval.php http://master.php.net/manage/user-notes.php?action=edit+25946 http://master.php.net/manage/user-notes.php?action=delete+25946 http://master.php.net/manage/user-notes.php?action=reject+25946

« previous php.notes (#37967) next »