note 93691 added to function.create-function
| From: | mmw at osu1 dot php dot net | Date: | Wed, 23 Sep 2009 02:54:07 +0000 |
| Subject: | note 93691 added to function.create-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160964@lists.php.net to get a copy of this message | ||
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));
?>
----
Server IP: 64.71.164.2
Probable Submitter: 24.5.1.26
----
Manual Page -- http://www.php.net/manual/en/function.create-function.php
Edit -- https://master.php.net/note/edit/93691
Del: integrated -- https://master.php.net/note/delete/93691/integrated
Del: useless -- https://master.php.net/note/delete/93691/useless
Del: bad code -- https://master.php.net/note/delete/93691/bad+code
Del: spam -- https://master.php.net/note/delete/93691/spam
Del: non-english -- https://master.php.net/note/delete/93691/non-english
Del: in docs -- https://master.php.net/note/delete/93691/in+docs
Del: other reasons-- https://master.php.net/note/delete/93691
Reject -- https://master.php.net/note/reject/93691
Search -- https://master.php.net/manage/user-notes.php