From 3eaca2c3590f0d08203754d8cf443eb2090e2d07 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 20 Mar 2026 21:07:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=8F=82=E6=95=B0=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器基础类中添加了对引用参数默认值的支持检查 - 当检测到引用参数具有默认值时抛出致命错误 - 添加了深度递归测试文件以验证递归函数功能 - 测试包含阶乘、斐波那契、相互递归和树形递归等场景 - 验证了分治算法如快速排序的递归实现 --- src/Php/CompilerBase.php | 3 + tests/aot/deep-recursion.phpt | 137 ++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/aot/deep-recursion.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 32a6e8a6..b5be87cf 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1023,6 +1023,9 @@ class CompilerBase extends \PhpAot\Core\Translator $argInfo->nullable = true; } if ($param->default) { + if ($param->byRef) { + $this->fatalError($param, 'Default value for parameters passed by reference is not supported'); + } $defaultValueCount++; $argInfo->default = $this->parseParamDefaultValue($param->default); $argInfo->defaultValue = $param->default; diff --git a/tests/aot/deep-recursion.phpt b/tests/aot/deep-recursion.phpt new file mode 100644 index 00000000..0605b763 --- /dev/null +++ b/tests/aot/deep-recursion.phpt @@ -0,0 +1,137 @@ +--TEST-- +Deep Recursion Test +--FILE-- + 1, + 'children' => [ + [ + 'value' => 2, + 'children' => [ + ['value' => 4, 'children' => []], + ['value' => 5, 'children' => []], + ], + ], + [ + 'value' => 3, + 'children' => [ + ['value' => 6, 'children' => []], + ], + ], + ], + ]; + + var_dump(sumTree($tree)); + + $unsorted = [3, 6, 1, 5, 2, 4]; + var_dump(quicksort($unsorted)); +} +?> +--EXPECT-- +int(120) +int(3628800) +int(89) +int(987) +bool(true) +bool(false) +bool(false) +bool(true) +int(21) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +}