fix(compiler): 支持数组和属性数组追加同时链式赋值

pull/8/head
Yurun 2 months ago
parent 8684d1652c
commit c59184bed7
  1. 5
      src/Php/CompilerBase.php
  2. 2
      src/Php/Parser/AssignOpTrait.php
  3. 45
      tests/aot/basic/multi-var-assign-chained.phpt

@ -2304,6 +2304,11 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont
protected function detectVarType($var): string
{
// Unwrap ArrayDimFetch to get the underlying variable type;
// the dim/index does not affect the base variable's type.
if ($var instanceof Expr\ArrayDimFetch) {
return $this->detectVarType($var->var);
}
$name = $this->parseIdentifier($var);
if ($this->isStdContainer($name)) {
return self::TYPE_ARRAY;

@ -272,6 +272,8 @@ trait AssignOpTrait
return $this->parseStdContainerAssign($left, $right);
}
return $this->parseAssignArrayDim($left, $right);
} elseif ($this->isArrayDimFetch($left) and $this->isPropertyFetch($left->var)) {
return $this->parseAssignPropertyArrayDim($left, $right);
}
if ($propertyWriteTarget !== null) {

@ -0,0 +1,45 @@
--TEST--
Chained assignment with array append ([]), property write, and variable write as rvalue inside constructor argument
--FILE--
<?php
class Test2
{
public function __construct($value2)
{
var_dump($value2);
}
}
class Test
{
public $arr = [];
public $value;
public function __construct()
{
$arr = [0];
new Test2($this->arr[] = $arr[] = $this->value = $value = 1);
var_dump($this->value, $value, $this->arr, $arr);
}
}
function main()
{
new Test;
}
?>
--EXPECT--
int(1)
int(1)
int(1)
array(1) {
[0]=>
int(1)
}
array(2) {
[0]=>
int(0)
[1]=>
int(1)
}
Loading…
Cancel
Save