From d1c4e365b194e5f0c05e1da34978613715393bd2 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 16 Jun 2026 16:38:06 +0800 Subject: [PATCH] =?UTF-8?q?test(const):=20=E6=B7=BB=E5=8A=A0=E7=B1=BB?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E9=BB=98=E8=AE=A4=E5=80=BC=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了类常量默认值从 self::CV 获取的测试用例 - 测试静态方法和实例方法中使用类常量作为参数默认值 - 验证了函数调用时传入不同参数的输出结果 - 修复了类常量默认值非字符串类型时的导出问题 - 确保默认值能正确转换为字符串格式进行显示 --- src/gen_stub.php | 3 +++ tests/aot/const/004.phpt | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/aot/const/004.phpt diff --git a/src/gen_stub.php b/src/gen_stub.php index 3565b900..5e82c458 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -4930,6 +4930,9 @@ function parseFunctionLike( if ($param->default instanceof Expr\ClassConstFetch && $param->default->class->toLowerString() === "self") { $defaultValue = getTranslator()->getClassConstValue($func, $name->className->name, $param->default->name->name); + if (!is_string($defaultValue)) { + $defaultValue = var_export($defaultValue, true); + } } else { $defaultValue = $param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null; } diff --git a/tests/aot/const/004.phpt b/tests/aot/const/004.phpt new file mode 100644 index 00000000..9686ee43 --- /dev/null +++ b/tests/aot/const/004.phpt @@ -0,0 +1,33 @@ +--TEST-- +class const default value from self::CV +--FILE-- +bbb(); + $t->bbb(888); +} +?> +--EXPECT-- +int(1) +int(999) +int(1) +int(888)