diff --git a/examples/micro_bench.php b/examples/micro_bench.php index 3ccf990c..50be6743 100644 --- a/examples/micro_bench.php +++ b/examples/micro_bench.php @@ -188,27 +188,27 @@ function read_auto_global($n) { } } -function read_global_var($n) { +function read_global_var(int $n) { for ($i = 0; $i < $n; ++$i) { $x = $GLOBALS['g_var']; } } -function read_hash($n) { +function read_hash(int $n) { $hash = array('test' => 0); for ($i = 0; $i < $n; ++$i) { $x = $hash['test']; } } -function read_str_offset($n) { +function read_str_offset(int $n) { $str = "test"; for ($i = 0; $i < $n; ++$i) { $x = $str[1]; } } -function issetor($n) { +function issetor(int $n) { $val = array(0,1,2,3,4,5,6,7,8,9); for ($i = 0; $i < $n; ++$i) { $x = $val ?: null; diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index a49b6e2b..67ac7fd5 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2284,6 +2284,13 @@ class CompilerBase extends \PhpAot\Core\Translator if ($node->dim === null) { $this->fatalError($node, 'Cannot use [] for GLOBALS'); } + if ($this->isScalarString($node->dim)) { + $name = $node->dim->value; + if (!$this->hasGlobalVar($name)) { + $this->addGlobalVar($name, self::TYPE_VAR); + } + return $name; + } return 'php::global(' . $this->parseIdentifier($node->dim) . ')'; } if (!$this->hasVar($var)) {