From c53e7afdb59cb5db0255d12159357142fc03f562 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 3 Apr 2026 14:54:52 +0800 Subject: [PATCH] =?UTF-8?q?test(lang):=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=20bug=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 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 函数调用优化处理 --- phpunit/code/re-assign-this.php | 15 +++++++++ phpunit/src/ClassTest.php | 10 ++++++ phpunit/src/FunctionTest.php | 1 + src/Php/CompilerBase.php | 2 +- src/Php/FuncCallOptimizer.php | 3 ++ tests/core/lang/bug21094.phpt | 17 ++++++++++ tests/core/lang/bug21961.phpt | 58 +++++++++++++++++++++++++++++++++ tests/core/lang/bug23624.phpt | 12 +++++++ tests/core/lang/bug26869.phpt | 15 +++++++++ tests/core/lang/bug30726.phpt | 8 +++++ 10 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 phpunit/code/re-assign-this.php create mode 100644 phpunit/src/ClassTest.php create mode 100644 tests/core/lang/bug21094.phpt create mode 100644 tests/core/lang/bug21961.phpt create mode 100644 tests/core/lang/bug23624.phpt create mode 100644 tests/core/lang/bug26869.phpt create mode 100644 tests/core/lang/bug30726.phpt diff --git a/phpunit/code/re-assign-this.php b/phpunit/code/re-assign-this.php new file mode 100644 index 00000000..bec6a611 --- /dev/null +++ b/phpunit/code/re-assign-this.php @@ -0,0 +1,15 @@ +Bar(); + echo "OK\n"; +} \ No newline at end of file diff --git a/phpunit/src/ClassTest.php b/phpunit/src/ClassTest.php new file mode 100644 index 00000000..de641eee --- /dev/null +++ b/phpunit/src/ClassTest.php @@ -0,0 +1,10 @@ +exec('Cannot re-assign $this', 're-assign-this.php'); + } + +} diff --git a/phpunit/src/FunctionTest.php b/phpunit/src/FunctionTest.php index c03ef514..b4bc779e 100644 --- a/phpunit/src/FunctionTest.php +++ b/phpunit/src/FunctionTest.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'); } + } diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 859e36a0..760809cd 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.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; diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 926dd2d5..8490e90e 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -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) . ')'; } diff --git a/tests/core/lang/bug21094.phpt b/tests/core/lang/bug21094.phpt new file mode 100644 index 00000000..dd901012 --- /dev/null +++ b/tests/core/lang/bug21094.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #21094 (set_error_handler not accepting methods) +--FILE-- + +--EXPECTF-- +[1024] errstr: test, errfile: %s, errline: %d diff --git a/tests/core/lang/bug21961.phpt b/tests/core/lang/bug21961.phpt new file mode 100644 index 00000000..48bd00b1 --- /dev/null +++ b/tests/core/lang/bug21961.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #21961 (get_parent_class() segfault) +--FILE-- +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" diff --git a/tests/core/lang/bug23624.phpt b/tests/core/lang/bug23624.phpt new file mode 100644 index 00000000..f8778fff --- /dev/null +++ b/tests/core/lang/bug23624.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #23624 (foreach leaves current array key as null) +--FILE-- + $value); + var_dump(current($arr)); +?> +--EXPECT-- +string(3) "one" +string(3) "one" diff --git a/tests/core/lang/bug26869.phpt b/tests/core/lang/bug26869.phpt new file mode 100644 index 00000000..065cf1dd --- /dev/null +++ b/tests/core/lang/bug26869.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #26869 (constant as the key of static array) +--FILE-- + 1); + var_dump($a); + var_dump(isset($a[A])); +?> +--EXPECT-- +array(1) { + [1]=> + int(1) +} +bool(true) diff --git a/tests/core/lang/bug30726.phpt b/tests/core/lang/bug30726.phpt new file mode 100644 index 00000000..79aeff7d --- /dev/null +++ b/tests/core/lang/bug30726.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #30726 (-.1 like numbers are not being handled correctly) +--FILE-- + +--EXPECT-- +1