3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { private $fruit = 'pear'; } function getfunc() { $b = function() { $a = function() { return 'apple'; }; echo $a(); return $this->fruit; }; $b->bindTo(new A()); return $b(); } echo getfunc();
based on oLVGt
Output for 7.0.0 - 7.2.0
apple Fatal error: Uncaught Error: Using $this when not in object context in /in/faS9c:11 Stack trace: #0 /in/faS9c(14): {closure}() #1 /in/faS9c(18): getfunc() #2 {main} thrown in /in/faS9c on line 11
Process exited with code 255.
Output for 5.4.0 - 5.6.28
apple Fatal error: Using $this when not in object context in /in/faS9c on line 11
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Fatal error: Call to undefined method Closure::bindTo() in /in/faS9c on line 13
Process exited with code 255.