3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo {} class Bar { private $foos; public function __construct(callable ...$foos) { $this->foos = $foos; } public function getFoo($id) : Foo { return $this->foos[$id](); } } class Baz { public function run($id) : Foo { return (new Bar( function(){ return new Foo; }, function(){ return new Foo; }, function(){ return new Foo; }, function(){ return new Foo; } ))->getFoo($id); } } var_dump((new Baz)->run(2));
Output for 7.0.0 - 7.3.0rc3
object(Foo)#7 (0) { }
Output for hhvm-3.22.0
Fatal error: Uncaught Error: Parameter $foos is variadic and has a type constraint (callable); variadic params with type constraints are not supported in non-Hack files in /in/mgLWH:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: Parameter $foos is variadic and has a type constraint (callable); variadic params with type constraints are not supported in non-Hack files in /in/mgLWH:9 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/mgLWH on line 14
Process exited with code 255.