3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $name; public function __construct($name) { $this->name = $name; } } $person = new A("Tim"); function test() { return $this->name; } $f = function() { return $this->name; }; $cl = Closure::fromCallable( $f ); echo $cl->bindTo($person, 'A')(); echo "\n\nBut, Closure::fromCallable problematic:\n"; try { $cl = Closure::fromCallable( "test" ); echo $cl->bindTo($person, 'A')(); } catch (Error $e) { echo "Unable to bind closure from callable because: \n"; echo $e->getMessage(); }
Output for 8.5.0 - 8.5.3
Tim But, Closure::fromCallable problematic: Warning: Cannot rebind scope of closure created from function, this will be an error in PHP 9 in /in/qso7b on line 26 Unable to bind closure from callable because: Value of type null is not callable
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18
Tim But, Closure::fromCallable problematic: Warning: Cannot rebind scope of closure created from function in /in/qso7b on line 26 Unable to bind closure from callable because: Value of type null is not callable
Output for 7.4.14 - 7.4.33
Tim But, Closure::fromCallable problematic: Warning: Cannot rebind scope of closure created from function in /in/qso7b on line 26 Unable to bind closure from callable because: Function name must be a string
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.13
Tim But, Closure::fromCallable problematic: Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in /in/qso7b on line 26 Unable to bind closure from callable because: Function name must be a string
Output for 7.0.0 - 7.0.33
Fatal error: Uncaught Error: Call to undefined method Closure::fromCallable() in /in/qso7b:19 Stack trace: #0 {main} thrown in /in/qso7b on line 19
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /in/qso7b on line 20
Process exited with code 255.

preferences:
97.9 ms | 2014 KiB | 4 Q