From fd48162ab640151e3b3d8c043094b8c470f858b4 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 17 Mar 2026 12:00:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在parseNativeMethodCall周围添加try-catch块以捕获PlaceHolder异常 - 当捕获到PlaceHolder异常时返回占位符数组 - 更新测试用例预期输出结果 - 添加新的占位符功能测试用例 --- src/Php/CompilerBase.php | 6 ++++- tests/aot/native-type.phpt | 4 +++- tests/aot/place-holder-002.phpt | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/aot/place-holder-002.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index faad75b1..f898c572 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3528,7 +3528,11 @@ class CompilerBase extends \PhpAot\Core\Translator $nativeFunc = $this->findNativeMethod($expr, $object, $this->parseIdentifier($expr->name)); if ($nativeFunc) { $expr->setAttribute('nativeCall', $nativeFunc); - return $this->parseNativeMethodCall($object, $nativeFunc, $expr->args); + try { + return $this->parseNativeMethodCall($object, $nativeFunc, $expr->args); + } catch (PlaceHolder) { + return $this->genPlaceHolder($this->genArray([$object, $method])); + } } } diff --git a/tests/aot/native-type.phpt b/tests/aot/native-type.phpt index afa92536..467a361e 100644 --- a/tests/aot/native-type.phpt +++ b/tests/aot/native-type.phpt @@ -15,4 +15,6 @@ function main() } ?> --EXPECT-- -float(2.5) +int(100) +float(100) +bool(true) diff --git a/tests/aot/place-holder-002.phpt b/tests/aot/place-holder-002.phpt new file mode 100644 index 00000000..67ed626d --- /dev/null +++ b/tests/aot/place-holder-002.phpt @@ -0,0 +1,41 @@ +--TEST-- +place-holder +--FILE-- +mainSocket = 'tcp-stream'; + } + + public function resumeAccept() + { + static::$globalEvent->onReadable($this->mainSocket, $this->acceptUdpConnection(...)); + } + + protected function acceptUdpConnection($stream) + { + var_dump(__METHOD__); + var_dump($stream); + } +} + +function main() +{ + $obj = new Worker; + Worker::$globalEvent = new Select; + $obj->resumeAccept(); +} +?> +--EXPECT-- +string(27) "Worker::acceptUdpConnection" +string(10) "tcp-stream" +