From 580f1fb64f2fe73e46e7b13ece1b22c7aaf42808 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 1 Jul 2026 21:33:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0=E6=98=AF=E5=AF=B9=E8=B1=A1=E6=97=B6?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/CompilerBase.php | 3 +- tests/aot/ref/ref-object.phpt | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/aot/ref/ref-object.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index c216b715..9cb58bb4 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -5806,7 +5806,8 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont // 可转为原生调用的 MethodCall if ($this->isVarExpr($expr->var) and $this->isNamedMethod($expr->name)) { $type = $this->getVarType($object); - if (!$this->checkArgType($type, self::TYPE_OBJECT)) { + // 引用参数允许方法调用:有class信息走原生调用,无class信息走动态调用 + if (!$this->checkArgType($type, self::TYPE_OBJECT) and $type !== self::TYPE_REF) { $methodName = $expr->name->toString(); // 非对象类型可使用内置方法 $fn = $this->findUniversalMethodAnyType($type, $methodName); diff --git a/tests/aot/ref/ref-object.phpt b/tests/aot/ref/ref-object.phpt new file mode 100644 index 00000000..a12b8fde --- /dev/null +++ b/tests/aot/ref/ref-object.phpt @@ -0,0 +1,58 @@ +--TEST-- +Reference parameter with object type - property access and method call +--FILE-- +value); + var_dump($test->abc()); + $test->value = 456; + $test = clone $test; + $test->value = 789; +} + +function test2(&$test) +{ + var_dump($test->value); + var_dump($test->abc()); + $test->value = 456; + $test = clone $test; + $test->value = 789; +} + +function main() +{ + $test = new Test(); + $testOrigin = $test; + test1($test); + var_dump($test !== $testOrigin); + var_dump($testOrigin->value, $test->value); + + $test = new Test(); + $testOrigin = $test; + test2($test); + var_dump($test !== $testOrigin); + var_dump($testOrigin->value, $test->value); +} +?> +--EXPECTF-- +int(123) +string(3) "abc" +bool(true) +int(456) +int(789) +int(123) +string(3) "abc" +bool(true) +int(456) +int(789)