Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed713ae

Browse filesBrowse files
SpacePossumnicolas-grekas
authored andcommitted
[Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes
1 parent 948b44c commit ed713ae
Copy full SHA for ed713ae

File tree

2 files changed

+16
-1
lines changed
Filter options

2 files changed

+16
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php
+7-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php
+9Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.