fix(compiler): handle DynamicCall exception in method resolution

- Wrapped getNativeMethod calls in try-catch blocks to handle DynamicCall exceptions
- Return null when DynamicCall exception is caught during method resolution
- Added nativeFunc initialization to prevent undefined variable issues
- Ensures graceful failure when native method cannot be resolved dynamically
pull/34/head
韩天峰 1 month ago
parent 10df177e78
commit 871bf3a950
  1. 12
      src/CompilerBase.php
  2. 1
      src/Parser/MethodCallTrait.php

@ -1865,7 +1865,11 @@ class CompilerBase implements PropertyAccessContext
} else {
return null;
}
$function = $this->getNativeMethod($expr, $class, $method, false);
try {
$function = $this->getNativeMethod($expr, $class, $method, false);
} catch (DynamicCall) {
return null;
}
if ($function !== false) {
return $this->getFunction($function)->returnsByRef;
}
@ -1892,7 +1896,11 @@ class CompilerBase implements PropertyAccessContext
$class = $this->getNamespacedClassName($class);
}
$method = $this->parseIdentifier($expr->name);
$function = $this->getNativeMethod($expr, $class, $method, false);
try {
$function = $this->getNativeMethod($expr, $class, $method, false);
} catch (DynamicCall) {
return null;
}
if ($function !== false) {
return $this->getFunction($function)->returnsByRef;
}

@ -397,6 +397,7 @@ trait MethodCallTrait
'Method Call: ',
$object . '->' . $this->parseIdentifier($expr->name) . '()'
);
$nativeFunc = false;
try {
$nativeFunc = $this->findNativeMethod($expr, $object, $this->parseIdentifier($expr->name));
if ($nativeFunc) {

Loading…
Cancel
Save