fix(compiler): 拒绝所有$$语法而非仅特定表达式

pull/25/head
Yurun 1 month ago
parent 559a8860a0
commit 00023cc3de
  1. 8
      phpunit/code/variable-variable-arraydim.php
  2. 9
      phpunit/src/VariableVariableTest.php
  3. 2
      src/CompilerBase.php

@ -0,0 +1,8 @@
<?php
function variable_variable_with_array_dim(): void
{
$foo = ['bar' => 'hello'];
${$foo['bar']} = 'world';
echo $hello;
}

@ -0,0 +1,9 @@
<?php
class VariableVariableTest extends \BaseTest
{
public function testVariableVariableWithArrayDimThrowsUnsupportedError(): void
{
$this->exec('The `$$` syntax is not supported', 'variable-variable-arraydim.php');
}
}

@ -1273,7 +1273,7 @@ class CompilerBase implements PropertyAccessContext
protected function parseVariable(Variable $expr): string
{
if (is_object($expr->name) and $this->isVarExpr($expr->name)) {
if (is_object($expr->name)) {
$this->fatalError($expr, 'The `$$` syntax is not supported');
}
if ($this->isSuperGlobal($expr->name)) {

Loading…
Cancel
Save