<?php
class Foo {
private $bar = 'oh yea';
public function foo() {
return new class {
function bar() {
return $this->bar;
}
};
}
}
var_dump((new Foo)->foo()->bar());
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in /in/gZXQj on line 3
Notice: Undefined property: class@anonymous::$bar in /in/gZXQj on line 10
NULL