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

Merged
韩天峰 merged 2 commits from fix-$$ into master 1 month ago
  1. 8
      phpunit/code/variable-variable-arraydim.php
  2. 12
      phpunit/code/variable-variable-function-call.php
  3. 14
      phpunit/src/VariableVariableTest.php
  4. 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,12 @@
<?php
function variable_name(): string
{
return 'hello';
}
function variable_variable_with_function_call(): void
{
${variable_name()} = 'world';
echo $hello;
}

@ -0,0 +1,14 @@
<?php
class VariableVariableTest extends \BaseTest
{
public function testVariableVariableWithArrayDimThrowsUnsupportedError(): void
{
$this->exec('The `$$` syntax is not supported', 'variable-variable-arraydim.php');
}
public function testVariableVariableWithFunctionCallThrowsUnsupportedError(): void
{
$this->exec('The `$$` syntax is not supported', 'variable-variable-function-call.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_string($expr->name)) {
$this->fatalError($expr, 'The `$$` syntax is not supported');
}
if ($this->isSuperGlobal($expr->name)) {

Loading…
Cancel
Save