-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug] Developer friendly Class Not Found and Undefined Function errors #8553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The biggest different with the original PR is that there is no hardcoded class map anymore. Instead, we use the well-known autoloaders to find class candidates. I have also refactored the code to make more flexible and easily testable. |
This makes #8281 a little bit more difficult as everything added in this PR really only belongs to the dev environement. |
One proposal (related to what we are doing here -- but can be done in another PR) would be to move the Beside being more consistent in terms of where the features belongs, it also makes sense as the Symfony ClassLoader component is less used than before as autoloading is now mostly done by Composer. What do you think about that? |
How does it works with Interfaces and Traits? Does the message is contextualized? Edit: It's perfect. fabpot@6671945#L0R270 |
Interfaces and traits are supported and the message is contextualized. |
+1 for moving the debug class loader to the Debug component. It would also remove the optional dependency from the debug component |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename the class to ClassNotFoundHandler
to be shorter and avoid repeating the namespace. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way it is named now is how we do it elsewhere, so this is consistent.
This PR was merged into the master branch. Discussion ---------- [Debug] Developer friendly Class Not Found and Undefined Function errors This is a followup of #8156 | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8156 | License | MIT | Doc PR | n/a Here is the original description from #8156: Per a discussion with @weaverryan and others, I took a crack at enhancing the exception display for class not found errors and undefined function errors. It is not the cleanest solution but this is a work in progress to see whether or not following this path makes sense. # Class Names ## Class Not Found: Unknown Class (Global Namespace) ```php <?php new WhizBangFactory(); ``` > Attempted to load class 'WhizBangFactory' from the global namespace in foo.php line 12. Did you forget a use statement for this class? ## Class Not Found: Unknown Class (Full Namespace) ```php <?php namespace Foo\Bar; new WhizBangFactory(); ``` > Attempted to load class 'WhizBangFactory' from namespace 'Foo\Bar' in foo.php line 12. Do you need to 'use' it from another namespace? ## Class Not Found: Well Known Class (Global Namespace) ```php <?php new Request(); ``` > Attempted to load class 'Request' from the global namespace in foo.php line 12. Did you forget a use statement for this class? Perhaps you need to add 'use Symfony\Component\HttpFoundation\Request' at the top of this file? ## Class Not Found: Well Known Class (Full Namespace) ```php <?php namespace Foo\Bar; new Request(); ``` > Attempted to load class 'Request' from namespace 'Foo\Bar' in foo.php line 12. Do you need to 'use' it from another namespace? Perhaps you need to add 'use Symfony\Component\HttpFoundation\Request' at the top of this file? # Functions ## Undefined Function (Global Namespace) ```php <?php // example.php: // namespace Acme\Example; // function test_namespaced_function() // { // } include "example.php"; test_namespaced_function() ``` > Attempted to call function 'test_namespaced_function' from the global namespace in foo.php line 12. Did you mean to call: '\acme\example\test_namespaced_function'? ## Undefined Function (Full Namespace) ```php <?php namespace Foo\Bar\Baz; // example.php: // namespace Acme\Example; // function test_namespaced_function() // { // } include "example.php"; test_namespaced_function() ``` > Attempted to call function 'test_namespaced_function' from namespace 'Foo\Bar\Baz' in foo.php line 12. Did you mean to call: '\acme\example\test_namespaced_function'? ## Undefined Function: Unknown Function (Global Namespace) ```php <?php test_namespaced_function() ``` > Attempted to call function 'test_namespaced_function' from the global namespace in foo.php line 12. ## Undefined Function: Unknown Function (Full Namespace) ```php <?php namespace Foo\Bar\Baz; test_namespaced_function() ``` > Attempted to call function 'test_namespaced_function' from namespace 'Foo\Bar\Baz' in foo.php line 12. Commits ------- bde67f0 fixed an error message 80e19e2 [Debug] added some missing phpdocs 968764b [Debug] refactored unit tests cefa1b5 [Debug] moved special fatal error handlers to their own classes 53ab284 [Debug] made Debug find FQCN automatically based on well-known autoloaders 208ca5f [Debug] made guessing of possible class names more flexible a0b1585 [Debug] fixed CS 6671945 Developer friendly Class Not Found and Undefined Function errors.
This PR was merged into the master branch. Discussion ---------- duplicated the DebugClassLoader in the Debug component | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This is a follow-up for #8553. Commits ------- d146461 duplicated the DebugClassLoader in the Debug component
This is a followup of #8156
Here is the original description from #8156:
Per a discussion with @weaverryan and others, I took a crack at enhancing the exception display for class not found errors and undefined function errors. It is not the cleanest solution but this is a work in progress to see whether or not following this path makes sense.
Class Names
Class Not Found: Unknown Class (Global Namespace)
Class Not Found: Unknown Class (Full Namespace)
Class Not Found: Well Known Class (Global Namespace)
Class Not Found: Well Known Class (Full Namespace)
Functions
Undefined Function (Global Namespace)
Undefined Function (Full Namespace)
Undefined Function: Unknown Function (Global Namespace)
Undefined Function: Unknown Function (Full Namespace)