3v4l.org

run code in 500+ PHP versions simultaneously
<?php function ghost_func_num_args(string $class, string $method, array $vars = []) { return count(ghost_func_get_args($class, $method, $vars)); } function ghost_func_get_args(string $class, string $method, array $vars = []) { $argc = 0; $argv = []; $reflectionMethod = new ReflectionMethod($class, $method); foreach ($reflectionMethod->getParameters() as $parameter) { $name = $parameter->getName(); $values = $vars[$name] ?? null; if (! $parameter->isVariadic()) { $argv[$parameter->getPosition()] = $values; ++$argc; continue; } foreach ($values as $value) { $argv[$argc++] = $value; } } return $argv; } function ghost_func_get_named_args(string $class, string $method, array $vars = []) { $argv_named = []; $reflectionMethod = new ReflectionMethod($class, $method); foreach ($reflectionMethod->getParameters() as $parameter) { $name = $parameter->getName(); $values = $vars[$name] ?? null; if (! $parameter->isVariadic()) { $argv_named[$name] = $values; continue; } foreach ($values as $key => $value) { $argv_named[$key] = $value; } } return $argv_named; } class User { public function register($email, $password, $active = null, $default = 0, ...$attributes) { $__mockery__vars = get_defined_vars(); $argc = ghost_func_num_args(__CLASS__, __FUNCTION__, $__mockery__vars); $argv = ghost_func_get_args(__CLASS__, __FUNCTION__, $__mockery__vars); $argv_named = ghost_func_get_named_args(__CLASS__, __FUNCTION__, $__mockery__vars); print_r([ '$argc' => $argc, '$argv' => $argv, '$argv_named' => $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 git.master, git.master_jit
Array ( [$argc] => 7 [$argv] => Array ( [0] => admin@test.com [1] => pass1 [2] => [3] => 0 [4] => uuid-1 [5] => 012-345-6789 [6] => admin ) [$argv_named] => Array ( [email] => admin@test.com [password] => pass1 [active] => [default] => 0 [id] => uuid-1 [phone] => 012-345-6789 [role] => admin ) ) -------- Array ( [$argc] => 8 [$argv] => Array ( [0] => test@test.com [1] => pass2 [2] => [3] => 0 [4] => uuid-2 [5] => 987-654-3210 [6] => first last2 [7] => tester ) [$argv_named] => Array ( [email] => test@test.com [password] => pass2 [active] => [default] => 0 [id] => uuid-2 [phone] => 987-654-3210 [name] => first last2 [role] => tester ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.38 ms | 2992 KiB | 4 Q