From d3360d2f38d81fbe4fa0a3fcdeeacf25f7bf0225 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 26 Jan 2026 19:10:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=B1=BB=E5=9E=8B=E8=BF=94=E5=9B=9E=E5=92=8Cinclude?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Expr_Array 的类型返回从 'php::Array' 改为 self::TYPE_ARRAY - 将字符串 'array' 的类型映射从 'php::Array' 改为 self::TYPE_ARRAY - 更新 parseInclude 方法参数类型为 Node\Expr\Include_ - 添加对不同 include 类型 (include, require, include_once, require_once) 的支持 - 在 include 表达式中传递正确的类型参数 - 添加 include 测试用例和相关测试文件 --- src/Php/CompilerBase.php | 24 ++++++++++++++++++++---- tests/aot/include.phpt | 12 ++++++++++++ tests/aot/test_include.inc | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/aot/include.phpt create mode 100644 tests/aot/test_include.inc diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 37ed2777..ffbc2adb 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1052,7 +1052,7 @@ class CompilerBase extends \PhpAot\Core\Translator case 'Scalar_Bool': return self::TYPE_BOOL; case 'Expr_Array': - return 'php::Array'; + return self::TYPE_ARRAY; case 'Expr_BinaryOp_Plus': case 'Expr_BinaryOp_Minus': case 'Expr_BinaryOp_Mul': @@ -1151,7 +1151,7 @@ class CompilerBase extends \PhpAot\Core\Translator case 'int': return self::TYPE_INT; case 'array': - return 'php::Array'; + return self::TYPE_ARRAY; case 'float': return self::TYPE_FLOAT; case 'bool': @@ -2317,9 +2317,25 @@ class CompilerBase extends \PhpAot\Core\Translator return 'php::eval(' . $this->parseIdentifier($expr->expr) . ')'; } - protected function parseInclude(mixed $expr): string + protected function parseInclude(Node\Expr\Include_ $expr): string { - return 'php::include(' . $this->parseIdentifier($expr->expr) . ')'; + switch ($expr->type) { + case Node\Expr\Include_::TYPE_INCLUDE: + $type = 'php::INCLUDE'; + break; + case Node\Expr\Include_::TYPE_INCLUDE_ONCE: + $type = 'php::INCLUDE_ONCE'; + break; + case Node\Expr\Include_::TYPE_REQUIRE: + $type = 'php::REQUIRE'; + break; + case Node\Expr\Include_::TYPE_REQUIRE_ONCE: + $type = 'php::REQUIRE_ONCE'; + break; + default: + $this->fatalError($expr, 'Invalid include type'); + } + return 'php::include(' . $this->parseIdentifier($expr->expr) . ', '. $type . ')'; } protected function parseBreak(mixed $v): string diff --git a/tests/aot/include.phpt b/tests/aot/include.phpt new file mode 100644 index 00000000..1264fd77 --- /dev/null +++ b/tests/aot/include.phpt @@ -0,0 +1,12 @@ +--TEST-- +strlen +--FILE-- + +--EXPECT-- +test_include.inc +test_include.inc \ No newline at end of file diff --git a/tests/aot/test_include.inc b/tests/aot/test_include.inc new file mode 100644 index 00000000..ac5621d2 --- /dev/null +++ b/tests/aot/test_include.inc @@ -0,0 +1,2 @@ +