I'd like to be able to dynamically create an instance method within a class' constructor like so:
class Foo{
function __construct() {
$code = 'print hi;';
$sayHi = create_function( '', $code);
print "$sayHi"; //prints lambda_2
print $sayHi(); // prints 'hi'
$this->sayHi = $sayHi;
}
}
$f = new Foo;
$f->sayHi(); //Fatal error: Call to undefined method Foo::sayHi() in /export/home/web/private/htdocs/staff/cohenaa/dev-drupal-2/sites/all/modules/devel/devel.module(1086) : eval()'d code on line 12
The problem seems to be that the lambda_2 function object is not getting bound to $this within the constructor.
Any help is appreciated.