From 04f265ae24d035078a9e48d15e09799e63ee6695 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 7 Jan 2026 16:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/div.php | 5 +-- main.cc | 4 +- run-tests.php | 1 + src/Php/Translator.php | 19 ++++++++++ tests/core/basic/001.phpt | 6 +++ tests/core/basic/006.phpt | 6 +++ tests/core/basic/007.phpt | 6 +++ tests/core/basic/008.phpt | 6 +++ tests/core/basic/009.phpt | 6 +++ tests/core/basic/010.phpt | 6 +++ tests/core/basic/012.phpt | 23 +++++++++++ tests/core/basic/bug80384.phpt | 28 ++++++++++++++ .../basic/consistent_float_string_casts.phpt | 31 +++++++++++++++ tests/core/basic/encoding.phpt | 38 +++++++++++++++++++ .../indirect_call_array_001.phpt | 14 +++++++ .../indirect_call_array_002.phpt | 14 +++++++ 16 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 tests/core/basic/001.phpt create mode 100644 tests/core/basic/006.phpt create mode 100644 tests/core/basic/007.phpt create mode 100644 tests/core/basic/008.phpt create mode 100644 tests/core/basic/009.phpt create mode 100644 tests/core/basic/010.phpt create mode 100644 tests/core/basic/012.phpt create mode 100644 tests/core/basic/bug80384.phpt create mode 100644 tests/core/basic/consistent_float_string_casts.phpt create mode 100644 tests/core/basic/encoding.phpt create mode 100644 tests/zend/indirect_function_call/indirect_call_array_001.phpt create mode 100644 tests/zend/indirect_function_call/indirect_call_array_002.phpt diff --git a/examples/div.php b/examples/div.php index 62fec320..99bd9c74 100644 --- a/examples/div.php +++ b/examples/div.php @@ -1,8 +1,7 @@ detectVarType($node->var); $rightExprStr = $this->convertExprType($expr, $type, $this->detectExprType($node->expr)); if ($this->isAssignOpConcat($op)) { + if ($this->isArrayVar($node->var)) { + $this->fatalError($node->var, 'Cannot concat string to array'); + } return $var . '.append(' . $rightExprStr . ')'; } elseif ($this->isAssignOpPow($op)) { $powExpr = 'php::call(php::pow, {' . $var . ', ' . $rightExprStr . '})'; @@ -2272,6 +2275,17 @@ class Translator extends \PhpAot\Core\Translator $this->indentLevel--; $code .= $this->genFunction(self::PREFIX . 'init_constant_vars', 'void', [], $lines); + // 生成全局变量 + $code .= PHP_EOL; + $this->indentLevel++; + $lines = []; + foreach ($this->globalVars as $name => $type) { + $lines[] = $this->getIndent() . $name . ' = php::global("' . $name . '");'; + } + $this->indentLevel--; + $code .= $this->genFunction(self::PREFIX . 'init_global_vars', 'void', [], $lines); + + // 销毁全局变量 $code .= PHP_EOL; $this->indentLevel++; $lines = []; @@ -2588,4 +2602,9 @@ class Translator extends \PhpAot\Core\Translator } return self::TYPE_VAR; } + + private function isArrayVar($var): bool + { + return $var->getType() == self::EXPR_VARIABLE and $this->hasVar($var->name) and $this->getVarType($var->name) == self::TYPE_ARRAY; + } } diff --git a/tests/core/basic/001.phpt b/tests/core/basic/001.phpt new file mode 100644 index 00000000..92790b9b --- /dev/null +++ b/tests/core/basic/001.phpt @@ -0,0 +1,6 @@ +--TEST-- +Trivial "Hello World" test +--FILE-- + +--EXPECT-- +Hello World diff --git a/tests/core/basic/006.phpt b/tests/core/basic/006.phpt new file mode 100644 index 00000000..6f0d01fd --- /dev/null +++ b/tests/core/basic/006.phpt @@ -0,0 +1,6 @@ +--TEST-- +Add 3 variables together and print result +--FILE-- + +--EXPECT-- +6 diff --git a/tests/core/basic/007.phpt b/tests/core/basic/007.phpt new file mode 100644 index 00000000..1d819b29 --- /dev/null +++ b/tests/core/basic/007.phpt @@ -0,0 +1,6 @@ +--TEST-- +Multiply 3 variables and print result +--FILE-- + +--EXPECT-- +64 diff --git a/tests/core/basic/008.phpt b/tests/core/basic/008.phpt new file mode 100644 index 00000000..84323086 --- /dev/null +++ b/tests/core/basic/008.phpt @@ -0,0 +1,6 @@ +--TEST-- +Divide 3 variables and print result +--FILE-- + +--EXPECT-- +3 diff --git a/tests/core/basic/009.phpt b/tests/core/basic/009.phpt new file mode 100644 index 00000000..f5f010fc --- /dev/null +++ b/tests/core/basic/009.phpt @@ -0,0 +1,6 @@ +--TEST-- +Subtract 3 variables and print result +--FILE-- + +--EXPECT-- +10 diff --git a/tests/core/basic/010.phpt b/tests/core/basic/010.phpt new file mode 100644 index 00000000..69117762 --- /dev/null +++ b/tests/core/basic/010.phpt @@ -0,0 +1,6 @@ +--TEST-- +Testing | and & operators +--FILE-- + +--EXPECT-- +8 diff --git a/tests/core/basic/012.phpt b/tests/core/basic/012.phpt new file mode 100644 index 00000000..37e5ecd8 --- /dev/null +++ b/tests/core/basic/012.phpt @@ -0,0 +1,23 @@ +--TEST-- +Testing $argc and $argv handling (cli) +--INI-- +register_argc_argv=1 +variables_order=GPS +--ARGS-- +ab cd ef 123 test +--FILE-- + +--EXPECT-- +0: ab +1: cd +2: ef +3: 123 +4: test diff --git a/tests/core/basic/bug80384.phpt b/tests/core/basic/bug80384.phpt new file mode 100644 index 00000000..cf30e860 --- /dev/null +++ b/tests/core/basic/bug80384.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #80384 large reads cause filters to internally buffer large amounts of memory +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) diff --git a/tests/core/basic/consistent_float_string_casts.phpt b/tests/core/basic/consistent_float_string_casts.phpt new file mode 100644 index 00000000..f4a80a71 --- /dev/null +++ b/tests/core/basic/consistent_float_string_casts.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test that float to string and string to float casts are consistent +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0,33 diff --git a/tests/core/basic/encoding.phpt b/tests/core/basic/encoding.phpt new file mode 100644 index 00000000..dbf61db9 --- /dev/null +++ b/tests/core/basic/encoding.phpt @@ -0,0 +1,38 @@ +--TEST-- +PHP encoding setting test +--FILE-- + +--EXPECT-- +string(5) "UTF-8" +string(0) "" +string(0) "" +string(0) "" +string(5) "UTF-8" +string(10) "ISO-8859-1" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(0) "" +string(6) "EUC-JP" +string(6) "EUC-JP" +string(6) "EUC-JP" diff --git a/tests/zend/indirect_function_call/indirect_call_array_001.phpt b/tests/zend/indirect_function_call/indirect_call_array_001.phpt new file mode 100644 index 00000000..aa896ff6 --- /dev/null +++ b/tests/zend/indirect_function_call/indirect_call_array_001.phpt @@ -0,0 +1,14 @@ +--TEST-- +Indirect method call by array - Invalid class name +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Invalid callback a::b, class "a" not found in %s +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/tests/zend/indirect_function_call/indirect_call_array_002.phpt b/tests/zend/indirect_function_call/indirect_call_array_002.phpt new file mode 100644 index 00000000..c8b28ada --- /dev/null +++ b/tests/zend/indirect_function_call/indirect_call_array_002.phpt @@ -0,0 +1,14 @@ +--TEST-- +Indirect method call by array - Invalid method name +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Invalid callback stdclass::b, class stdClass does not have a method "b" in %s +Stack trace: +#0 {main} + thrown in %s on line %d