3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* Function Argument Unpacking in PHP 5.6 complements Variadic Functions! */ class Foo { public function __construct($arg1, $arg2, $arg3) { /* Do stuff constructor with arguments */ $this->arg1 = $arg1; $this->arg2 = $arg2; $this->arg3 = $arg3; } } class Bar extends Foo { public function __construct(...$args) { /** * Before argument unpacking in 5.6 we would use * call_user_func_array + func_get_args to accomplish * the same thing. */ // The intent here is to call the parent constructor parent::__construct(...$args); // Looks much nicer in 5.6 } } $bar = new Bar(1,2,3); var_dump($bar);
Output for 5.6.8 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
object(Bar)#1 (3) { ["arg1"]=> int(1) ["arg2"]=> int(2) ["arg3"]=> int(3) }
Output for 5.4.0 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/6ibqf on line 13
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/6ibqf on line 13
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '.', expecting '&' or T_VARIABLE in /in/6ibqf on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/6ibqf on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/6ibqf on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/6ibqf on line 4
Process exited with code 255.