8000 bug #21010 [Debug] UndefinedMethodFatalErrorHandler - Handle anonymou… · symfony/symfony@ee69018 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit ee69018

Browse files
bug #21010 [Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes (SpacePossum)
This PR was squashed before being merged into the 2.7 branch (closes #21010). Discussion ---------- [Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT When trying to call a method on an anonymous class (with or without methods) the `UndefinedMethodFatalErrorHandler` tries to iterate `null`. For ref.: https://3v4l.org/l26u1 Commits ------- ed713ae [Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes
2 parents eeb9192 + ed713ae commit ee69018

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ public function handleError(array $error, FatalErrorException $exception)
3636

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

39+
if (!class_exists($className) || null === $methods = get_class_methods($className)) {
40+
// failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
41+
return new UndefinedMethodException($message, $exception);
42+
}
43+
3944
$candidates = array();
40-
foreach (get_class_methods($className) as $definedMethodName) {
45+
foreach ($methods as $definedMethodName) {
4146
$lev = levenshtein($methodName, $definedMethodName);
4247
if ($lev <= strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
4348
$candidates[] = $definedMethodName;
@@ -52,6 +57,7 @@ public function handleError(array $error, FatalErrorException $exception)
5257
} else {
5358
$candidates = '"'.$last;
5459
}
60+
5561
$message .= "\nDid you mean to call ".$candidates;
5662
}
5763

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ public function provideUndefinedMethodData()
6161
),
6262
"Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
6363
),
64+
array(
65+
array(
66+
'type' => 1,
67+
'message' => 'Call to undefined method class@anonymous::test()',
68+
'file' => '/home/possum/work/symfony/test.php',
69+
'line' => 11,
70+
),
71+
'Attempted to call an undefined method named "test" of class "class@anonymous".',
72+
),
6473
);
6574
}
6675
}

0 commit comments

Comments
 (0)
0