I am having a class and I have a dynamically created function (created via "create_function") but I cannot find a way to tell PHP that I want this function to be created for this class only (class function) and because of that the new function cannot access the object properties. Take a look at the following code:
class Test {
private $var=1;
function __construct() {
call_user_func(create_function('', 'echo $this->var;'));
}
}
new Test;
This throws error "Fatal error: Using $this when not in object context in D:\WWW\index.php(7) : runtime-created function on line 1"
You probably want runkit_method_add, not create_function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With