Comments By: John McKnight
-
Part of that code got clipped. Not sure what happened but it should have looked like this. class TestLambda { private $test; public function __construct() { $this->test = create_function('$str', 'echo $str;'); } // (John McKnight) This magic method checks for the existence of a function that may have been created using create_function. // Normal methods are unaffected by this code so they should run without issue also. function __call($name, $args) { if (!isset($this->$name)) { echo "Undefined function '{$name}'"; } $function = $this->$name; if (function_exists($function)) { call_user_func_array($function, $args); } } } $l = new TestLambda; // (John McKnight) - But now it works. $l->test("hello world");posted on Jun 21, 2008 at 4:27pm | context
-
#2 can be made to work using the __call magic method.posted on Jun 21, 2008 at 4:20am | context
test = create_function('$str', 'echo $str;'); } // (John McKnight) This magic method checks for the existence of a function that may have been created using create_function. // Normal methods are unaffected by this code so they should run without issue also. function __call($name, $args) { if (!isset($this->$name)) { echo "Undefined function '{$name}'"; } $function = $this->$name; if (function_exists($function)) { call_user_func_array($function, $args); } } } $l = new TestLambda; // (John McKnight) - But now it works. $l->test("hello world"); ?>