test(lang): 添加多个 bug 修复测试用例

- 添加 Bug #21094 关于 set_error_handler 不接受方法的测试
- 添加 Bug #21961 关于 get_parent_class() 段错误的测试
- 添加 Bug #23624 关于 foreach 留下当前数组键为 null 的测试
- 添加 Bug #26869 关于常量作为静态数组键的测试
- 添加 Bug #30726 关于 -.1 类似数字处理不当的测试
- 添加 Cannot re-assign $this 的测试用例和相关代码文件
- 更新编译器默认原生类型设置为 true
- 添加 strlen 函数调用优化处理
pull/1/head
韩天峰 5 months ago
parent a8483af474
commit c53e7afdb5
  1. 15
      phpunit/code/re-assign-this.php
  2. 10
      phpunit/src/ClassTest.php
  3. 1
      phpunit/src/FunctionTest.php
  4. 2
      src/Php/CompilerBase.php
  5. 3
      src/Php/FuncCallOptimizer.php
  6. 17
      tests/core/lang/bug21094.phpt
  7. 58
      tests/core/lang/bug21961.phpt
  8. 12
      tests/core/lang/bug23624.phpt
  9. 15
      tests/core/lang/bug26869.phpt
  10. 8
      tests/core/lang/bug30726.phpt

@ -0,0 +1,15 @@
<?php
class Foo {
function Bar() {
$__this = $this;
$this = null;
debug_backtrace();
$this = $__this;
}
}
function main() {
$f = new Foo;
$f->Bar();
echo "OK\n";
}

@ -0,0 +1,10 @@
<?php
class ClassTest extends \BaseTest
{
public function testReAssignThis()
{
$this->exec('Cannot re-assign $this', 're-assign-this.php');
}
}

@ -6,4 +6,5 @@ class FunctionTest extends \BaseTest
{
$this->exec('The return type of the function `test` cannot be a reference type', 'function-return-ref.php');
}
}

@ -245,7 +245,7 @@ class CompilerBase extends \PhpAot\Core\Translator
protected string $buildDir;
protected int $debugLine = 0;
protected CLImate $climate;
protected bool $defaultNativeType = false;
protected bool $defaultNativeType = true;
protected bool $stubFile = false;
protected bool $enableProfiler = false;
protected bool $forTest = false;

@ -85,6 +85,9 @@ trait FuncCallOptimizer
if ($name === 'pow') {
return 'php::math::pow(' . $getArg(0) . ', ' . $getArg(1) . ')';
}
if ($name === 'strlen') {
return 'php::fn::strlen(' . $getArg(0) . ')';
}
if ($name === 'ord') {
return 'php::fn::ord(' . $getArg(0) . ')';
}

@ -0,0 +1,17 @@
--TEST--
Bug #21094 (set_error_handler not accepting methods)
--FILE--
<?php
class test {
function hdlr($errno, $errstr, $errfile, $errline) {
printf("[%d] errstr: %s, errfile: %s, errline: %d\n", $errno, $errstr, $errfile, $errline, $errstr);
}
}
function main() {
set_error_handler(array(new test(), "hdlr"));
trigger_error("test");
}
?>
--EXPECTF--
[1024] errstr: test, errfile: %s, errline: %d

@ -0,0 +1,58 @@
--TEST--
Bug #21961 (get_parent_class() segfault)
--FILE--
<?php
class man
{
public $name, $bars;
function __construct()
{
$this->name = 'Mr. X';
$this->bars = array();
}
function getdrunk($where)
{
$this->bars[] = new bar($where);
}
function getName()
{
return $this->name;
}
}
class bar extends man
{
public $name;
function __construct($w)
{
$this->name = $w;
}
function getName()
{
return $this->name;
}
function whosdrunk()
{
$who = get_parent_class($this);
if($who == NULL)
{
return 'nobody';
}
return eval("return ".$who.'::getName();');
}
}
function main() {
$x = new man;
$x->getdrunk('The old Tavern');
var_dump($x->bars[0]->whosdrunk());
}
?>
--EXPECT--
string(14) "The old Tavern"

@ -0,0 +1,12 @@
--TEST--
Bug #23624 (foreach leaves current array key as null)
--FILE--
<?php
$arr = array ('one', 'two', 'three');
var_dump(current($arr));
foreach($arr as $key => $value);
var_dump(current($arr));
?>
--EXPECT--
string(3) "one"
string(3) "one"

@ -0,0 +1,15 @@
--TEST--
Bug #26869 (constant as the key of static array)
--FILE--
<?php
define("A", "1");
static $a=array(A => 1);
var_dump($a);
var_dump(isset($a[A]));
?>
--EXPECT--
array(1) {
[1]=>
int(1)
}
bool(true)

@ -0,0 +1,8 @@
--TEST--
Bug #30726 (-.1 like numbers are not being handled correctly)
--FILE--
<?php
echo (int) is_float('-.1' * 2), "\n";
?>
--EXPECT--
1
Loading…
Cancel
Save