fix(php): 修复原生方法调用异常处理

- 在parseNativeMethodCall周围添加try-catch块以捕获PlaceHolder异常
- 当捕获到PlaceHolder异常时返回占位符数组
- 更新测试用例预期输出结果
- 添加新的占位符功能测试用例
pull/1/head
韩天峰 6 months ago
parent 6d9c3da0c0
commit fd48162ab6
  1. 6
      src/Php/CompilerBase.php
  2. 4
      tests/aot/native-type.phpt
  3. 41
      tests/aot/place-holder-002.phpt

@ -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]));
}
}
}

@ -15,4 +15,6 @@ function main()
}
?>
--EXPECT--
float(2.5)
int(100)
float(100)
bool(true)

@ -0,0 +1,41 @@
--TEST--
place-holder
--FILE--
<?php
class Select {
public function onReadable($stream, callable $func): void
{
$func($stream);
}
}
class Worker {
public static ?EventInterface $globalEvent = null;
protected $mainSocket;
function __construct() {
$this->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"
Loading…
Cancel
Save