3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public function publicMethod() { return function() use ($this) { return $this->privateMethod(); }; } private function privateMethod() { return 'works'; } } $test = new Test; $testFunction = $test->publicMethod(); echo $testFunction();
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.30
Fatal error: Cannot use $this as lexical variable in /in/5Nb15 on line 7
Process exited with code 255.

preferences:
196.73 ms | 1395 KiB | 67 Q