merged branch stof/debug_class_loader (PR #6803)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #6803).
Commits
-------
be05741 Added an error message in the DebugClassLoader when using / instead of \.
Discussion
----------
Added an error message in the DebugClassLoader when using / instead of \.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR | n/a
Using ``/`` instead of ``\`` when writing class names in a configuration seems to happen regularly. See aba8f1e180 (commitcomment-2461266)
for the latest case I saw. I guess it may come from the fact that SensioGeneratorBundle allows using both for convenience in the CLI to get rid of escaping issues.
This will give people a better error message when they use a ``/`` instead of having them figure that the class name in the message using ``/`` and not ``\`` and this is the reason of the issue.
This commit is contained in:
commit
84c6b486d1
@ -82,6 +82,10 @@ class DebugClassLoader
|
|||||||
require $file;
|
require $file;
|
||||||
|
|
||||||
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
|
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
|
||||||
|
if (false !== strpos($class, '/')) {
|
||||||
|
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".'));
|
||||||
|
}
|
||||||
|
|
||||||
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
|
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user