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); echo $ob1->getClosure()->call($obj1); echo $ob2->getClosure()->call($ob2);
based on WY4Ft
Output for 7.0.0 - 7.2.0
Notice: Undefined variable: obj1 in /in/4APXg on line 16 Warning: Closure::call() expects parameter 1 to be object, null given in /in/4APXg on line 16 2
Output for 5.3.22 - 5.6.28
Fatal error: Call to undefined method Closure::call() in /in/4APXg on line 16
Process exited with code 255.