From 2912b40b0f23700d0f4fb7f081803f0200e5f00d Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 23 Apr 2026 13:04:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81=E5=92=8C=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=8E=B7=E5=8F=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器基础类中添加了 Expr_PropertyFetch 表达式处理逻辑 - 实现了原生属性变量检测和类型推断功能 - 新增了属性获取表达式的原生属性变量标记机制 - 更新了多个示例文件以使用 native_types 命名空间 - 添加了默认数组属性测试用例验证功能 - 集成了 polyfills 支持并在主入口点传递命令行参数 --- bin/compiler.php | 1 + cli.php | 2 +- examples/bench.php | 2 ++ examples/pi.php | 2 ++ src/Php/CompilerBase.php | 11 +++++++++++ tests/aot/object_property/003.phpt | 25 +++++++++++++++++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/aot/object_property/003.phpt diff --git a/bin/compiler.php b/bin/compiler.php index 45ec141d..93dabdc4 100755 --- a/bin/compiler.php +++ b/bin/compiler.php @@ -1,6 +1,7 @@ #!/usr/bin/env php isVarExpr($expr->var) and $this->isIdExpr($expr->name)) { + $this->parsePropertyFetch($expr); + if ($expr->getAttribute('nativePropertyVar')) { + $propVar = $expr->getAttribute('nativePropertyVar'); + $info = $this->context->objectProps[$propVar]; + return $info['type']; + } + } + break; case 'Expr_New': return self::TYPE_OBJECT; case 'Expr_Assign': @@ -3465,6 +3475,7 @@ class CompilerBase extends \PhpAot\Core\Translator 'getter' => $getProperty, ]; } + $expr->setAttribute('nativePropertyVar', $propVar); return $propVar; } } diff --git a/tests/aot/object_property/003.phpt b/tests/aot/object_property/003.phpt new file mode 100644 index 00000000..0e605843 --- /dev/null +++ b/tests/aot/object_property/003.phpt @@ -0,0 +1,25 @@ +--TEST-- +default array property +--FILE-- +x; + $x += 23; + $this->x += 12; + var_dump($x, $this->x); + } +} + +function main() { + $obj = new Test; + $obj->bar(); +} +?> +--EXPECT-- +int(123) +int(112) \ No newline at end of file