test(compiler): 添加多个 bug 修复测试用例并修复全局变量解析问题

- 添加 bug #24499 测试用例,验证公共属性被误处理为私有属性的问题
- 添加 bug #24652 测试用例,修复 array_flip 函数的 broken 问题
- 添加 bug #24908 测试用例,解决超全局变量在 __destruct 中无法使用的问题
- 添加 bug #55754 测试用例,修复 ZEND_SEND_PREFER_REF 参数的引用传递问题
- 修复 CompilerBase.php 中全局变量解析逻辑,确保变量名正确转义
pull/1/head
韩天峰 5 months ago
parent 8312de6c73
commit e1fd716e03
  1. 2
      src/Php/CompilerBase.php
  2. 27
      tests/core/lang/bug24499.phpt
  3. 31
      tests/core/lang/bug24652.phpt
  4. 20
      tests/core/lang/bug24908.phpt
  5. 14
      tests/core/lang/bug55754.phpt

@ -3151,7 +3151,7 @@ class CompilerBase extends \PhpAot\Core\Translator
protected function parseGlobal(Node\Stmt\Global_ $v): string
{
foreach ($v->vars as $v) {
$name = $this->escapeVarName($v->name);
$name = $this->escapeVarName($this->parseVariable($v));
if (!$this->hasGlobalVar($name)) {
$this->addGlobalVar($name, self::TYPE_VAR);
}

@ -0,0 +1,27 @@
--TEST--
Bug #24499 (bogus handling of a public property as a private one)
--FILE--
<?php
class Id {
private $id="priv";
public function tester($obj)
{
$obj->id = "bar";
}
}
function main() {
$id = new Id();
$obj = new stdClass;
$obj->foo = "bar";
$id->tester($obj);
print_r($obj);
}
?>
--EXPECT--
stdClass Object
(
[foo] => bar
[id] => bar
)

@ -0,0 +1,31 @@
--TEST--
Bug #24652 (broken array_flip())
--FILE--
<?php
/* This works */
$f = array('7' => 0);
var_dump($f);
var_dump(array_key_exists(7, $f));
var_dump(array_key_exists('7', $f));
print "----------\n";
/* This doesn't */
$f = array_flip(array('7'));
var_dump($f);
var_dump(array_key_exists(7, $f));
var_dump(array_key_exists('7', $f));
?>
--EXPECT--
array(1) {
[7]=>
int(0)
}
bool(true)
bool(true)
----------
array(1) {
[7]=>
int(0)
}
bool(true)
bool(true)

@ -0,0 +1,20 @@
--TEST--
Bug #24908 (super-globals cannot be used in __destruct())
--INI--
variables_order=GPS
--FILE--
<?php
class test {
function __construct() {
if (count($_SERVER)) echo "O";
}
function __destruct() {
if (count($_SERVER)) echo "K\n";
}
}
function main() {
$test = new test();
}
?>
--EXPECT--
OK

@ -0,0 +1,14 @@
--TEST--
Bug #55754 (Only variables should be passed by reference for ZEND_SEND_PREFER_REF params)
--FILE--
<?php
current($arr = array(0 => "a"));
current(array(0 => "a"));
current($arr);
echo "DONE";
?>
--EXPECT--
DONE
Loading…
Cancel
Save