note 93691 deleted from function.create-function by danbrown

From: Date: Wed, 23 Sep 2009 02:56:05 +0000
Subject: note 93691 deleted from function.create-function by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160965@lists.php.net to get a copy of this message
Note Submitter: mmw ---- In answer to Stefan and co, sure this is far to be perfect. <?php class Object { private $block; // @runtime reserved final public function addBlock($name, $arguments, $code) { $this->block[$name]['arguments'] = $arguments; $this->block[$name]['body'] = $code; } // @runtime reserved final public function invokeBlock($name, $arguments) { // Object context cannot call private methods if (isset( $this->block[$name])) { if (is_array($arguments)) { $arg_names = explode(',', $this->block[$name]['arguments']); for ($i = 0; $i < count($arg_names); $i++) { eval($arg_names[$i]." = ".$arguments[$i].";"); } } return eval($this->block[$name]['body']); } return null; } }; class myObject extends Object { protected function callme($a, $b) { echo get_class($this)." ".($a + $b)."\n"; } }; $obj = new myObject; $obj->addBlock('aBlock', '$a, $b', '$this->callme($a, $b);'); $obj->invokeBlock('aBlock', array(1, 3)); ?>

« previous php.notes (#160965) next »