3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $fn = function(){ return $this->getFoo(); }; class Bar{ private $foo = 3; public function getFoo(){ return $this->foo; } } $fn->bindTo(new Bar); echo $fn();
based on K0PkC
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/6Cmsv:3 Stack trace: #0 /in/6Cmsv(16): {closure}() #1 {main} thrown in /in/6Cmsv on line 3
Process exited with code 255.
Output for 5.4.12 - 5.6.28
Fatal error: Using $this when not in object context in /in/6Cmsv on line 3
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Fatal error: Call to undefined method Closure::bindTo() in /in/6Cmsv on line 14
Process exited with code 255.