From 157bbec4fd773bae53c5483c50951a5530a2cc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Wed, 27 Jan 2021 17:03:07 +0100 Subject: [PATCH] [ErrorHandler] Fix strpos error when trying to call a method without a name --- FatalErrorHandler/UndefinedMethodFatalErrorHandler.php | 2 +- .../UndefinedMethodFatalErrorHandlerTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php b/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php index 773f4df..4f622de 100644 --- a/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php +++ b/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php @@ -40,7 +40,7 @@ public function handleError(array $error, FatalErrorException $exception) $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); - if (!class_exists($className) || null === $methods = get_class_methods($className)) { + if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) { // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class) return new UndefinedMethodException($message, $exception); } diff --git a/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index 55f2f62..160dc7f 100644 --- a/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -48,6 +48,15 @@ public function provideUndefinedMethodData() ], 'Attempted to call an undefined method named "what" of class "SplObjectStorage".', ], + [ + [ + 'type' => 1, + 'line' => 12, + 'file' => 'foo.php', + 'message' => 'Call to undefined method SplObjectStorage::()', + ], + 'Attempted to call an undefined method named "" of class "SplObjectStorage".', + ], [ [ 'type' => 1,