From af5442f25e349b5cea2194fc548b95bfce18915b Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sun, 15 Mar 2026 12:21:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E7=B1=BB?= =?UTF-8?q?=E4=BD=9C=E7=94=A8=E5=9F=9F=E5=A4=84=E7=90=86=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=89=8D=E7=BC=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBase.php 中添加 ltrim 函数移除命名空间前导反斜杠 - 为私有属性访问添加新的测试用例 private-prop-001.phpt - 测试验证静态类属性读写功能的正确性 --- src/Php/CompilerBase.php | 2 +- tests/aot/private-prop-001.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/aot/private-prop-001.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 3c013f32..a927bcb9 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3586,7 +3586,7 @@ class CompilerBase extends \PhpAot\Core\Translator if ($namespace) { $findClass = $namespace . '\\' . $class; } - $scope = $this->class ? $namespace . '\\' . $class : ''; + $scope = $this->class ? ltrim($namespace . '\\' . $class, '\\') : ''; while (true) { if ($this->hasNativeClass($findClass)) { diff --git a/tests/aot/private-prop-001.phpt b/tests/aot/private-prop-001.phpt new file mode 100644 index 00000000..a7682cc4 --- /dev/null +++ b/tests/aot/private-prop-001.phpt @@ -0,0 +1,29 @@ +--TEST-- +Static Class Property Read/Write Test +--FILE-- +errorHandler = $errorHandler; + var_dump($this->errorHandler); + } +} + +class Worker +{ + public static ?stdClass $globalEvent = null; + + public static function init() { + self::$globalEvent = new Select; + self::$globalEvent->setErrorHandler('test'); + } +} + +function main() { + Worker::init(); +} +?> +--EXPECT-- +string(4) "test" \ No newline at end of file