From 871bf3a950b7a1918a5cad457ec571db73bde2cf Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sun, 19 Jul 2026 21:10:51 +0800 Subject: [PATCH] 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 --- src/CompilerBase.php | 12 ++++++++++-- src/Parser/MethodCallTrait.php | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/CompilerBase.php b/src/CompilerBase.php index e5355646..4b556df5 100644 --- a/src/CompilerBase.php +++ b/src/CompilerBase.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; } diff --git a/src/Parser/MethodCallTrait.php b/src/Parser/MethodCallTrait.php index 6ede7f2c..4a8eeef6 100644 --- a/src/Parser/MethodCallTrait.php +++ b/src/Parser/MethodCallTrait.php @@ -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) {