3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * composer require nikic/php-parser */ require __DIR__ . '/vendor/autoload.php'; use PhpParser\ParserFactory; /** * 获取调用函数的参数 * * @param array $backtrace debug_backtrace * @param string $func 要查找的函数名字 * * @return array 返回调用的参数,如果是变量,就返回变量名,如果不是变量是值,就返回序列号,从参数索引 0 开始编号 */ function getCallFuncArgs(array $backtrace, string $func): array { // 获取调用栈中第一个 $caller = array_shift($backtrace); // 取出文件 $file = $caller['file']; // 创建解析器 $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); $code = file_get_contents($file); // 解析代码 $ast = $parser->parse($code); $nodeFinder = new \PhpParser\NodeFinder(); // 查找所有的函数调用 $nodes = $nodeFinder->findInstanceOf($ast, \PhpParser\Node\Expr\FuncCall::class); $argList = []; foreach ($nodes as $node) { // 找到函数名跟要查找的一致的 if (($node->name->parts[0] ?? null) === $func) { // 创建索引值 $i = 0; // 遍历所有参数 foreach ($node->args as $arg) { // 如果是变量,就取变量名 if ($arg->value instanceof \PhpParser\Node\Expr\Variable) { $argList[] = $arg->value->name; } else { // 否则就编号 $argList[] = '#' . $i; } $i++; } } } return $argList; } function testA() { // 调用 $keys = getCallFuncArgs(debug_backtrace(), __FUNCTION__); // 填充一个关联数组,创建关系 $combine = array_combine($keys, func_get_args()); var_dump($combine); } $a = 1; $b = 2; $c = 2; testA($a, $b, 1, 2, 3, 4, $c);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.130.0100.01018.64
8.4.120.0130.00618.88
8.4.110.0110.00918.94
8.4.100.0120.00718.04
8.4.90.0110.01020.67
8.4.80.0060.00218.84
8.4.70.0110.01218.83
8.4.60.0130.01020.62
8.4.50.0120.00620.42
8.4.40.0100.00920.59
8.4.30.0100.01018.55
8.4.20.0100.01020.69
8.4.10.0160.00323.80
8.3.250.0040.00518.49
8.3.240.0110.00416.74
8.3.230.0130.00716.83
8.3.220.0040.00518.71
8.3.210.0110.00816.86
8.3.200.0110.00616.85
8.3.190.0110.00917.10
8.3.180.0080.01118.70
8.3.170.0070.01118.88
8.3.160.0070.01120.69
8.3.150.0090.00916.73
8.3.140.0130.00616.73
8.3.130.0130.00617.06
8.3.120.0110.00719.06
8.3.110.0030.00520.94
8.3.100.0060.00324.06
8.3.90.0000.00826.77
8.3.80.0090.00020.64
8.3.70.0070.01517.00
8.3.60.0100.01018.68
8.3.50.0140.00717.05
8.3.40.0040.01119.96
8.3.30.0060.01018.84
8.3.20.0080.00024.18
8.3.10.0080.00024.66
8.3.00.0000.00826.16
8.2.290.0120.00817.32
8.2.280.0120.00718.50
8.2.270.0120.00618.38
8.2.260.0050.00517.30
8.2.250.0000.00816.48
8.2.240.0060.01218.83
8.2.230.0070.01322.58
8.2.220.0000.01037.54
8.2.210.0000.00826.77
8.2.200.0030.00616.88
8.2.190.0090.00916.63
8.2.180.0100.00716.63
8.2.170.0150.00018.82
8.2.160.0130.00622.96
8.2.150.0080.00025.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0050.00319.43
8.2.110.0060.00322.07
8.2.100.0070.00418.89
8.1.330.0070.00416.27
8.1.320.0130.00618.10
8.1.310.0060.00916.85
8.1.300.0050.00517.91
8.1.290.0060.00318.88
8.1.280.0060.00925.92
8.1.270.0070.00024.66
8.1.260.0030.00626.35
8.1.250.0050.00328.09
8.1.240.0030.00619.04
8.1.230.0090.00018.52
8.1.140.0090.00919.52
7.4.330.0120.00514.58

preferences:
23.37 ms | 403 KiB | 5 Q