fix(php): 为方法调用添加异常处理以解决动态调用问题

- 在 findNativeMethod 调用周围添加 try-catch 块
- 捕获 DynamicCall 异常以处理内部类继承的方法
- 添加注释说明无法静态解析类型的情况
- 保持原有逻辑在非异常情况下的正常执行流程
pull/1/head
韩天峰 3 months ago
parent 403991357e
commit c8e6f2ecc4
  1. 12
      src/Php/CompilerBase.php

@ -2094,10 +2094,14 @@ class CompilerBase extends \PhpAot\Core\Translator
}
if ($this->isVarExpr($expr->var)) {
$object = $this->parseIdentifier($expr->var);
$nativeFunc = $this->findNativeMethod($expr, $object, $method);
if ($nativeFunc) {
$funcDef = $this->getFunction($nativeFunc);
return $funcDef->returnType;
try {
$nativeFunc = $this->findNativeMethod($expr, $object, $method);
if ($nativeFunc) {
$funcDef = $this->getFunction($nativeFunc);
return $funcDef->returnType;
}
} catch (DynamicCall) {
// Method inherited from internal class, can't resolve type statically
}
if ($this->isTypedObject($object)) {
return $this->detectMethodCallReturnType($this->getObjectType($object), $method);

Loading…
Cancel
Save