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 b00a488

Browse filesBrowse files
committed
[Debug] Parse "x not found" errors correctly on php 8.
1 parent 4351a70 commit b00a488
Copy full SHA for b00a488

File tree

1 file changed

+20
-36
lines changed
Filter options

1 file changed

+20
-36
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php
+20-36Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,34 @@ class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface
2929
*/
3030
public function handleError(array $error, FatalErrorException $exception)
3131
{
32-
$messageLen = \strlen($error['message']);
33-
$notFoundSuffix = '\' not found';
34-
$notFoundSuffixLen = \strlen($notFoundSuffix);
35-
if ($notFoundSuffixLen > $messageLen) {
32+
if (!preg_match('/^(Class|Interface|Trait) [\'"]([^\'"]+)[\'"] not found$/', $error['message'], $matches)) {
3633
return null;
3734
}
38-
39-
if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
40-
return null;
35+
$typeName = strtolower($matches[1]);
36+
$fullyQualifiedClassName = $matches[2];
37+
38+
if (false !== $namespaceSeparatorIndex = strrpos($fullyQualifiedClassName, '\\')) {
39+
$className = substr($fullyQualifiedClassName, $namespaceSeparatorIndex + 1);
40+
$namespacePrefix = substr($fullyQualifiedClassName, 0, $namespaceSeparatorIndex);
41+
$message = sprintf('Attempted to load %s "%s" from namespace "%s".', $typeName, $className, $namespacePrefix);
42+
$tail = ' for another namespace?';
43+
} else {
44+
$className = $fullyQualifiedClassName;
45+
$message = sprintf('Attempted to load %s "%s" from the global namespace.', $typeName, $className);
46+
$tail = '?';
4147
}
4248

43-
foreach (['class', 'interface', 'trait'] as $typeName) {
44-
$prefix = ucfirst($typeName).' \'';
45-
$prefixLen = \strlen($prefix);
46-
if (0 !== strpos($error['message'], $prefix)) {
47-
continue;
48-
}
49-
50-
$fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);
51-
if (false !== $namespaceSeparatorIndex = strrpos($fullyQualifiedClassName, '\\')) {
52-
$className = substr($fullyQualifiedClassName, $namespaceSeparatorIndex + 1);
53-
$namespacePrefix = substr($fullyQualifiedClassName, 0, $namespaceSeparatorIndex);
54-
$message = sprintf('Attempted to load %s "%s" from namespace "%s".', $typeName, $className, $namespacePrefix);
55-
$tail = ' for another namespace?';
49+
if ($candidates = $this->getClassCandidates($className)) {
50+
$tail = array_pop($candidates).'"?';
51+
if ($candidates) {
52+
$tail = ' for e.g. "'.implode('", "', $candidates).'" or "'.$tail;
5653
} else {
57-
$className = $fullyQualifiedClassName;
58-
$message = sprintf('Attempted to load %s "%s" from the global namespace.', $typeName, $className);
59-
$tail = '?';
54+
$tail = ' for "'.$tail;
6055
}
61-
62-
if ($candidates = $this->getClassCandidates($className)) {
63-
$tail = array_pop($candidates).'"?';
64-
if ($candidates) {
65-
$tail = ' for e.g. "'.implode('", "', $candidates).'" or "'.$tail;
66-
} else {
67-
$tail = ' for "'.$tail;
68-
}
69-
}
70-
$message .= "\nDid you forget a \"use\" statement".$tail;
71-
72-
return new ClassNotFoundException($message, $exception);
7356
}
57+
$message .= "\nDid you forget a \"use\" statement".$tail;
7458

75-
return null;
59+
return new ClassNotFoundException($message, $exception);
7660
}
7761

7862
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.