3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { private $name; public function __construct($name) { $this->name = $name; } } // test callable function getName() { return $this->name; } $bob = new A("Bob"); $cl1 = Closure::fromCallable("getName"); $cl1 = $cl1->bindTo($bob, 'A'); //This will retrieve: Uncaught Error: Cannot access private property A::$name $result = $cl1(); echo $result; //But for a Lambda function $cl2 = function() { return $this->name; }; $cl2 = $cl2->bindTo($bob, 'A'); $result = $cl2(); // This will print Bob echo $result;
Output for 7.1.0 - 7.3.0alpha1
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in /in/tq0lO on line 19 Fatal error: Uncaught Error: Function name must be a string in /in/tq0lO:22 Stack trace: #0 {main} thrown in /in/tq0lO on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.24
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/tq0lO:18 Stack trace: #0 {main} thrown in /in/tq0lO on line 18
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/tq0lO:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.15.4 - 3.21.3
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/tq0lO:18 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Call to undefined method Closure::fromCallable() in /in/tq0lO on line 18
Process exited with code 255.