test(compiler): cover expression variable names

pull/25/head
韩天峰 1 month ago
parent 00023cc3de
commit 848c763c0d
  1. 12
      phpunit/code/variable-variable-function-call.php
  2. 5
      phpunit/src/VariableVariableTest.php
  3. 2
      src/CompilerBase.php

@ -0,0 +1,12 @@
<?php
function variable_name(): string
{
return 'hello';
}
function variable_variable_with_function_call(): void
{
${variable_name()} = 'world';
echo $hello;
}

@ -6,4 +6,9 @@ class VariableVariableTest extends \BaseTest
{
$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)) {
if (!is_string($expr->name)) {
$this->fatalError($expr, 'The `$$` syntax is not supported');
}
if ($this->isSuperGlobal($expr->name)) {

Loading…
Cancel
Save