diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 2fca7b6f..1b41e3de 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -59,7 +59,6 @@ class Constants public const UNSUPPORTED_FUNCTIONS = [ 'compact', 'extract', - 'func_num_args', 'func_get_arg', 'func_get_args', ]; diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index be16620b..c1b330fa 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -56,6 +56,18 @@ trait FuncCallOptimizer if ($name === 'array_key_exists') { return $getArg(1) . '.offsetExists(' . $getArg(0) . ')'; } + if ($name === 'func_get_args') { + + } + if ($name === 'func_num_args') { + $funcDef = $this->functionDef; + foreach ($funcDef->argInfoList as $i => $argInfo) { + if ($argInfo->variadic) { + return '(' . $argInfo->name . '.count() + ' . $i . ')'; + } + } + return count($funcDef->argInfoList); + } if ($name === 'function_exists') { $funcName = $expr->args[0]->value; if ($this->isScalarString($funcName)) { diff --git a/tests/aot/functions/func_num_args.phpt b/tests/aot/functions/func_num_args.phpt new file mode 100644 index 00000000..d0650222 --- /dev/null +++ b/tests/aot/functions/func_num_args.phpt @@ -0,0 +1,29 @@ +--TEST-- +func_num_args +--FILE-- + +--EXPECT-- +int(3) +int(5) +int(6) \ No newline at end of file