[ErrorHandler] Fix strpos error when trying to call a method without a name

This commit is contained in:
Jérôme Deuchnord 2021-01-27 17:03:07 +01:00 committed by Nicolas Grekas
parent aeb15a1322
commit 66be87bffc
4 changed files with 15 additions and 2 deletions

View File

@ -40,7 +40,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); $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) // 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); return new UndefinedMethodException($message, $exception);
} }

View File

@ -48,6 +48,15 @@ class UndefinedMethodFatalErrorHandlerTest extends TestCase
], ],
'Attempted to call an undefined method named "what" of class "SplObjectStorage".', '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, 'type' => 1,

View File

@ -39,7 +39,7 @@ class UndefinedMethodErrorEnhancer implements ErrorEnhancerInterface
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); $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) // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
return new UndefinedMethodError($message, $error); return new UndefinedMethodError($message, $error);
} }

View File

@ -40,6 +40,10 @@ class UndefinedMethodErrorEnhancerTest extends TestCase
'Call to undefined method SplObjectStorage::what()', 'Call to undefined method SplObjectStorage::what()',
'Attempted to call an undefined method named "what" of class "SplObjectStorage".', 'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
], ],
[
'Call to undefined method SplObjectStorage::()',
'Attempted to call an undefined method named "" of class "SplObjectStorage".',
],
[ [
'Call to undefined method SplObjectStorage::walid()', 'Call to undefined method SplObjectStorage::walid()',
"Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?", "Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",