From 9c5bf37b6ff5598a09c078c073f6ee40752c4d26 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 1 Jul 2026 12:54:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(generator):=20=E4=BF=AE=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8=E4=B8=AD=E7=9A=84=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E4=BC=A0=E9=80=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在函数、参数、常量和属性的代码生成中添加refval包装器 - 确保use引用变量正确传递给代码生成函数 - 解决闭包中通过回调使用引用捕获的功能问题 - 添加测试用例验证闭包引用捕获的正确性 --- src/gen_stub.php | 10 +-- .../closure-use-reference-callback.phpt | 74 +++++++++++++++++++ 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 tests/aot/closure/closure-use-reference-callback.phpt diff --git a/src/gen_stub.php b/src/gen_stub.php index 0ba7faf2..bcf590e9 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -5555,7 +5555,7 @@ function generateFunctionAttributeInitialization(iterable $funcInfos, array $all "func_" . $funcInfo->name->getNameForAttributes() . "_$key", $allConstInfos, $phpVersionIdMinimumCompatibility, - $useDeclared + refval($useDeclared) ); } @@ -5566,7 +5566,7 @@ function generateFunctionAttributeInitialization(iterable $funcInfos, array $all "func_{$funcInfo->name->getNameForAttributes()}_arg{$index}_$key", $allConstInfos, $phpVersionIdMinimumCompatibility, - $useDeclared + refval($useDeclared) ); } } @@ -5627,7 +5627,7 @@ function generateGlobalConstantAttributeInitialization( $constVarName . "_$key", $allConstInfos, PHP_85_VERSION_ID, - $useDeclared + refval($useDeclared) ); } @@ -5675,7 +5675,7 @@ function generateConstantAttributeInitialization( "const_" . $constInfo->name->getDeclarationName() . "_$key", $allConstInfos, $phpVersionIdMinimumCompatibility, - $useDeclared + refval($useDeclared) ); } @@ -5705,7 +5705,7 @@ function generatePropertyAttributeInitialization( "property_" . $propertyInfo->name->getDeclarationName() . "_" . $key, $allConstInfos, $phpVersionIdMinimumCompatibility, - $declaredStrings + refval($declaredStrings) ); } } diff --git a/tests/aot/closure/closure-use-reference-callback.phpt b/tests/aot/closure/closure-use-reference-callback.phpt new file mode 100644 index 00000000..56f5f54f --- /dev/null +++ b/tests/aot/closure/closure-use-reference-callback.phpt @@ -0,0 +1,74 @@ +--TEST-- +Closure use reference capture through callbacks +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(6) "even:2" + [1]=> + string(6) "even:4" +} +string(9) "[1][2][3]" +array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) +} +string(3) "s_0" +string(3) "s_1" +string(3) "s_0" +array(2) { + ["alpha"]=> + string(3) "s_0" + ["beta"]=> + string(3) "s_1" +}