class someClass {
private $success = "success\n";
function getReflection() {
return new ReflectionFunction(function() {
print $this->success;
});
}
}
$reflection = (new someClass)->getReflection();
$reflection->invoke();
When I run this, I get a
Fatal error: Using $this when not in object context in Command line code on line 5
What's happening here? Why is $this not defined there...?
As I'm in a Closure inside a method, $this normally should be defined. And yes, I'm on a newer version than PHP 5.4.
How can I fix it?