diff --git a/phpunit/code/unset-array-dim-fetch-empty.php b/phpunit/code/unset-array-dim-fetch-empty.php new file mode 100644 index 00000000..67d9b0f1 --- /dev/null +++ b/phpunit/code/unset-array-dim-fetch-empty.php @@ -0,0 +1,6 @@ +exec('The variable `$u1` is undefined', 'undefined-vars-01.php'); $this->exec('Unsupported unset type `Expr_FuncCall`', 'unset-01.php'); } -} + + public function testUnsetEmptyArrayDimFetch() + { + $this->exec('Cannot use [] for array unset', 'unset-array-dim-fetch-empty.php'); + } +} \ No newline at end of file diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index c4aca94c..0c4386a1 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4037,6 +4037,9 @@ class CompilerBase extends \PhpAot\Core\Translator $lines = []; foreach ($vars as $var) { if ($this->isArrayDimFetch($var)) { + if ($var->dim === null) { + $this->fatalError($var, 'Cannot use [] for array unset'); + } $array = $this->parseIdentifier($var->var); $dim = $this->parseIdentifier($var->dim); $lines[] = $array . '.offsetUnset(' . $dim . ');'; @@ -5781,4 +5784,4 @@ class CompilerBase extends \PhpAot\Core\Translator return $tmpVar; } -} +} \ No newline at end of file