fix(php): 修复类作用域处理中的命名空间前缀问题

- 在 CompilerBase.php 中添加 ltrim 函数移除命名空间前导反斜杠
- 为私有属性访问添加新的测试用例 private-prop-001.phpt
- 测试验证静态类属性读写功能的正确性
pull/1/head
韩天峰 5 months ago
parent c259d20562
commit af5442f25e
  1. 2
      src/Php/CompilerBase.php
  2. 29
      tests/aot/private-prop-001.phpt

@ -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)) {

@ -0,0 +1,29 @@
--TEST--
Static Class Property Read/Write Test
--FILE--
<?php
class Select {
private $errorHandler = null;
public function setErrorHandler($errorHandler): void
{
$this->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"
Loading…
Cancel
Save