From 96b4fefb58cf6d7e9f28b4f6b86a9fb957bb30e6 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 9 Jun 2026 14:44:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E5=B0=86=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=92=8C=E7=BC=96=E8=AF=91=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=8ECompilerBase=E8=BF=81=E7=A7=BB=E5=88=B0Translator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从CompilerBase.php移除平台检测相关方法(detectPlatform, initializeNewArchitecture, setCppCompiler) - 从CompilerBase.php移除代码格式化方法(formatCppCode)和save方法 - 从CompilerBase.php移除编译命令选项相关方法(getCompileCommandOptions等) - 在Translator.php中新增平台检测方法(detectPlatform) - 在Translator.php中新增代码格式化方法(formatCppCode)和save方法 - 在Translator.php中新增编译命令选项相关方法(getCompileCommandOptions等) - 移除CompilerBase.php中未使用的SsaBuilder导入 - 在Translator.php中新增必要的平台和编译器工厂类导入 --- src/Php/Preprocessor.php | 9 ++++++++- tests/aot/type_hits/007.phpt | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/aot/type_hits/007.phpt diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index 7da54de0..aa7f5d7a 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -269,7 +269,14 @@ class Preprocessor extends CompilerBase if ($this->classDef->hasProperty($name)) { $this->fatalError($param, "Duplicate property `{$name}`"); } - $propertyDef = new PropertyDef($name, $param->flags, $type, $default, $nullable); + // 将类型标准化为内部类型格式(如 array -> php::Array) + if ($type instanceof NodeAbstract) { + $dummyClass = ''; + $propType = $this->parseTypeDecl($type, self::DECL_TYPE_OF_PROPERTY, $dummyClass); + } else { + $propType = $this->zendTypeMap[strtolower($type)] ?? self::TYPE_VAR; + } + $propertyDef = new PropertyDef($name, $param->flags, $propType, $default, $nullable); $this->classDef->properties[$name] = $propertyDef; } if ($param->variadic) { diff --git a/tests/aot/type_hits/007.phpt b/tests/aot/type_hits/007.phpt new file mode 100644 index 00000000..c0e29bd5 --- /dev/null +++ b/tests/aot/type_hits/007.phpt @@ -0,0 +1,33 @@ +--TEST-- +type hits +--FILE-- +collectLabels($this->stmts); + } +} + +function main() +{ + $obj = new Foo(['Hello World']); + $obj->buildCfg(); +} +?> +--EXPECT-- +array(1) { + [0]=> + string(11) "Hello World" +} \ No newline at end of file