diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 93ce84ab..c68d8b17 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -5889,7 +5889,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)