8000 [ErrorHandler] Fix strpos error when trying to call a method without … · symfony/symfony@66be87b · GitHub
[go: up one dir, main page]

Skip to content

Commit 66be87b

Browse files
Jérôme Deuchnordnicolas-grekas
Jérôme Deuchnord
authored andcommitted
[ErrorHandler] Fix strpos error when trying to call a method without a name
1 parent aeb15a1 commit 66be87b

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function handleError(array $error, FatalErrorException $exception)
4040

4141
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
4242

43-
if (!class_exists($className) || null === $methods = get_class_methods($className)) {
43+
if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) {
4444
// failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
4545
return new UndefinedMethodException($message, $exception);
4646
}

src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public function provideUndefinedMethodData()
4848
],
4949
'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
5050
],
51+
[
52+
[
53+
'type' => 1,
54+
'line' => 12,
55+
'file' => 'foo.php',
56+
'message' => 'Call to undefined method SplObjectStorage::()',
57+
],
58+
'Attempted to call an undefined method named "" of class "SplObjectStorage".',
59+
],
5160
[
5261
[
5362
'type' => 1,

src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function enhance(\Throwable $error): ?\Throwable
3939

4040
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
4141

42-
if (!class_exists($className) || null === $methods = get_class_methods($className)) {
42+
if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) {
4343
// failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
4444
return new UndefinedMethodError($message, $error);
4545
}

src/Symfony/Component/ErrorHandler/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function provideUndefinedMethodData()
4040
'Call to undefined method SplObjectStorage::what()',
4141
'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
4242
],
43+
[
44+
'Call to undefined method SplObjectStorage::()',
45+
'Attempted to call an undefined method named "" of class "SplObjectStorage".',
46+
],
4347
[
4448
'Call to undefined method SplObjectStorage::walid()',
4549
"Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",

0 commit comments

Comments
 (0)
0