From 1d6681ade3e38ec541941421d3e9f633378c968b Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 17 Mar 2026 12:55:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在原生函数调用周围添加 try-catch 块以处理 PlaceHolder 异常 - 添加对名称表达式类型的检查以正确解析静态方法调用 - 为动态类名静态方法调用实现字符串连接逻辑 - 添加静态方法调用功能的测试用例 --- src/Php/CompilerBase.php | 12 ++++++++++-- tests/aot/static-method-001.phpt | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/aot/static-method-001.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index f898c572..8e880d3b 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2207,7 +2207,11 @@ class CompilerBase extends \PhpAot\Core\Translator $nativeFn = $this->findNativeFunction($name); if ($nativeFn) { $expr->setAttribute('nativeCall', $nativeFn); - return self::PREFIX . $nativeFn . '(' . $this->parseNativeCallArgs($expr->args, $nativeFn) . ')'; + try { + return self::PREFIX . $nativeFn . '(' . $this->parseNativeCallArgs($expr->args, $nativeFn) . ')'; + } catch (PlaceHolder) { + return $this->genPlaceHolder($this->identifierToStr($expr->name)); + } } $code = $this->parseFuncCallWithOptimizer($name, $expr); if ($code) { @@ -3612,7 +3616,7 @@ class CompilerBase extends \PhpAot\Core\Translator $fn = 'php_get_called_ce(this_), php::getMethod(php_get_called_ce(this_), ' . $methodPtr . ')'; $this->beforeStmtLines[] = '// Static Method Call: static::' . $this->parseIdentifier($expr->name) . '()'; $placeHolder = $this->genArray(['php_get_called_class(this_)', $methodPtr]); - } else { + } elseif ($this->isNameExpr($expr->class)) { if ($class === 'self') { $class = $this->class; $self = true; @@ -3654,7 +3658,11 @@ class CompilerBase extends \PhpAot\Core\Translator $ce = $this->getClassEntryPtr($class); $fn = $ce . ', ' . $this->getFuncPtr($class . '::' . $method); $placeHolder = $this->genArray($callScope); + } else { + $fn = 'php::concat({' . $this->identifierToStr($expr->class) . ', "::", ' . $this->identifierToStr($expr->name) . '})'; + $placeHolder = $fn; } + $call = 'php::call'; if (empty($expr->args)) { return $call . '(' . $fn . ')'; diff --git a/tests/aot/static-method-001.phpt b/tests/aot/static-method-001.phpt new file mode 100644 index 00000000..6545ffb6 --- /dev/null +++ b/tests/aot/static-method-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +static method +--FILE-- +protocol::input('http1.1'); + } +} + +function main() { + $worker = new Worker(); + $worker->run(); +} +?> +--EXPECT-- +string(7) "http1.0" +string(7) "http1.1"