fix(php): 修复引用参数传递中的静态属性处理问题

- 在引用参数解析中添加临时变量处理以支持引用类型参数
- 为静态属性获取器添加 toReference() 方法调用支持
- 添加新的测试用例验证静态属性引用操作的正确性
- 优化编译器对 nativeProperty 属性的引用值处理逻辑
pull/3/head
韩天峰 2 months ago
parent 991e4bc931
commit 15bcacacc0
  1. 11
      src/Php/CompilerBase.php
  2. 41
      tests/aot/ref/ref-static-prop.phpt

@ -3055,7 +3055,10 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($this->isScalar($arg->value)) {
$this->fatalError($arg, 'The constants cannot be used as an argument for a reference-type parameter');
}
$list_args[] = $this->parseChainedExpr($arg->value, self::OP_REFVAL);
$tmpRef = $this->genTmpVarName();
$this->addLocalVar($tmpRef, self::TYPE_REF);
$this->context->beforeStmtLines[] = $tmpRef . ' = ' . $this->parseChainedExpr($arg->value, self::OP_REFVAL) . ';';
$list_args[] = '&' . $tmpRef;
continue;
}
}
@ -4478,12 +4481,18 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($this->isPropertyFetch($expr) and $this->isVarExpr($expr->var) and $this->isIdExpr($expr->name)) {
$prop = $this->parsePropertyFetch($expr);
if ($expr->hasAttribute('nativeProperty')) {
if ($op === self::OP_REFVAL) {
return $prop . '.toReference()';
}
return $fn . '(' . $prop . ')';
}
}
if ($this->isStaticPropertyFetch($expr) and $this->isNameExpr($expr->class) and $this->isIdExpr($expr->name)) {
$prop = $this->parseStaticPropertyFetch($expr);
if ($expr->hasAttribute('nativeProperty')) {
if ($op === self::OP_REFVAL) {
return $prop . '.toReference()';
}
return $fn . '(' . $prop . ')';
}
}

@ -0,0 +1,41 @@
--TEST--
object link operator
--FILE--
<?php
class StackHolder
{
public static array $stack = [];
public static function push(string $item): void
{
self::$stack[] = $item;
}
public static function pop(): void
{
array_pop(self::$stack);
}
public static function count(): int
{
return count(self::$stack);
}
}
function main(): int
{
StackHolder::push('a');
StackHolder::push('b');
StackHolder::pop();
if (StackHolder::count() !== 1) {
echo "FAIL: expected 1, got " . StackHolder::count() . "\n";
return 1;
}
echo "OK\n";
return 0;
}
?>
--EXPECT--
OK
Loading…
Cancel
Save