diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 34957002..bbf507fa 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -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; diff --git a/src/Php/Parser/AssignOpTrait.php b/src/Php/Parser/AssignOpTrait.php index 24661283..efb309fe 100644 --- a/src/Php/Parser/AssignOpTrait.php +++ b/src/Php/Parser/AssignOpTrait.php @@ -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) { diff --git a/tests/aot/basic/multi-var-assign-chained.phpt b/tests/aot/basic/multi-var-assign-chained.phpt new file mode 100644 index 00000000..ab8cf6ec --- /dev/null +++ b/tests/aot/basic/multi-var-assign-chained.phpt @@ -0,0 +1,45 @@ +--TEST-- +Chained assignment with array append ([]), property write, and variable write as rvalue inside constructor argument +--FILE-- +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) +}