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(); }

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
154.13 ms | 2619 KiB | 8 Q