3v4l.org

run code in 500+ PHP versions simultaneously
<?php class User { public function register($email, $password, $active = null, $default = 0, ...$attributes) { $defined_vars = get_defined_vars(); print_r(['$defined_vars'=>$defined_vars]); $argc = func_num_args(); $argv = func_get_args(); $__mockery__argc = 0; $__mockery__argv = []; $__mockery__argv_named = []; foreach ((new ReflectionMethod(__CLASS__, __FUNCTION__))->getParameters() as $__mockery__parameter) { $__mockery__name = $__mockery__parameter->getName(); $__mockery__values = $defined_vars[$__mockery__name]; unset($defined_vars[$__mockery__name]); if (! $__mockery__parameter->isVariadic()) { $__mockery__argv_named[$__mockery__name] = $__mockery__values; $__mockery__argv[$__mockery__parameter->getPosition()] = $__mockery__values; ++$__mockery__argc; continue; } foreach($__mockery__values as $__mockery__key => $__mockery__value) { $__mockery__argv_named[$__mockery__key] = $__mockery__value; $__mockery__argv[$__mockery__argc++] = $__mockery__value; } } print_r([ '$argc' => $argc, '$argv' => $argv, '$__mockery__argc'=>$__mockery__argc, '$__mockery__argv' => $__mockery__argv, '$__mockery__argv_named' => $__mockery__argv_named, ]); return [$email, $password, $attributes]; } } $foo = new User(); $foo->register('admin@test.com', 'pass1', ...[ 'id' => 'uuid-1', 'phone' => '012-345-6789', 'role' => 'admin', ]); echo PHP_EOL.'--------'.PHP_EOL; $foo->register(...[ 'id' => 'uuid-2', 'email' => 'test@test.com', 'phone' => '987-654-3210', 'name' => 'first last2', 'role' => 'tester', 'password' => 'pass2' ]);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.33, 8.3.0 - 8.3.33, 8.4.1 - 8.4.25, 8.5.0 - 8.5.10
Array ( [$defined_vars] => Array ( [email] => admin@test.com [password] => pass1 [active] => [default] => 0 [attributes] => Array ( [id] => uuid-1 [phone] => 012-345-6789 [role] => admin ) ) ) Array ( [$argc] => 2 [$argv] => Array ( [0] => admin@test.com [1] => pass1 ) [$__mockery__argc] => 7 [$__mockery__argv] => Array ( [0] => admin@test.com [1] => pass1 [2] => [3] => 0 [4] => uuid-1 [5] => 012-345-6789 [6] => admin ) [$__mockery__argv_named] => Array ( [email] => admin@test.com [password] => pass1 [active] => [default] => 0 [id] => uuid-1 [phone] => 012-345-6789 [role] => admin ) ) -------- Array ( [$defined_vars] => Array ( [email] => test@test.com [password] => pass2 [active] => [default] => 0 [attributes] => Array ( [id] => uuid-2 [phone] => 987-654-3210 [name] => first last2 [role] => tester ) ) ) Array ( [$argc] => 2 [$argv] => Array ( [0] => test@test.com [1] => pass2 ) [$__mockery__argc] => 8 [$__mockery__argv] => Array ( [0] => test@test.com [1] => pass2 [2] => [3] => 0 [4] => uuid-2 [5] => 987-654-3210 [6] => first last2 [7] => tester ) [$__mockery__argv_named] => Array ( [email] => test@test.com [password] => pass2 [active] => [default] => 0 [id] => uuid-2 [phone] => 987-654-3210 [name] => first last2 [role] => tester ) )
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/e1UK7:51 Stack trace: #0 {main} thrown in /in/e1UK7 on line 51
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Catchable fatal error: Cannot unpack array with string keys in /in/e1UK7 on line 54
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/e1UK7 on line 4
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/e1UK7 on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '.', expecting '&' or T_VARIABLE in /in/e1UK7 on line 4
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/e1UK7 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/e1UK7 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/e1UK7 on line 4
Process exited with code 255.

preferences:
75.88 ms | 3211 KiB | 4 Q