3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { function __construct($val) { $this->val = $val; } function getClosure() { //returns closure bound to this object and scope return function() { return $this->val; }; } } $ob1 = new A(1); $ob2 = new A(2); $cl = $ob1->getClosure(); echo $cl(), "\n"; echo $cl->call($ob2);
Output for 7.0.0 - 7.2.0
1 2
Output for 5.4.12 - 5.6.28
1 Fatal error: Call to undefined method Closure::call() in /in/WY4Ft on line 19
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Fatal error: Using $this when not in object context in /in/WY4Ft on line 9
Process exited with code 255.