3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $closure; public function __construct(callable $closure) { $this->closure = $closure; } public function run1(...$args) { ($this->closure)(...$args); } public function run2(...$args) { $this->closure(...$args); } } $foo = new Foo(function($var){ var_dump($var); }); $foo->run1('bar'); $foo->run2('bar'); $foo->run3('bar');
Output for 7.0.30 - 7.3.0beta1
string(3) "bar" Fatal error: Uncaught Error: Call to undefined method Foo::closure() in /in/D3YEa:17 Stack trace: #0 /in/D3YEa(26): Foo->run2('bar') #1 {main} thrown in /in/D3YEa on line 17
Process exited with code 255.
Output for hhvm-3.22.0
string(3) "bar" Fatal error: Uncaught Error: Call to undefined method Foo::closure() in /in/D3YEa:-1 Stack trace: #0 /in/D3YEa(-1): Foo->run2() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
string(3) "bar" Fatal error: Uncaught Error: Call to undefined method Foo::closure() in /in/D3YEa:17 Stack trace: #0 /in/D3YEa(26): Foo->run2() #1 {main}
Process exited with code 255.
Output for 5.6.30
Parse error: syntax error, unexpected '(' in /in/D3YEa on line 12
Process exited with code 255.