Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added an error message in the DebugClassLoader when using / instead of \. #6803

Closed
wants to merge 1 commit into from

2 participants

@stof
Collaborator
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 aba8f1e#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.

@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot 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 aba8f1e#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.
84c6b48
@fabpot fabpot closed this
@stof stof deleted the stof:debug_class_loader branch
@mmucklo mmucklo referenced this pull request from a commit
@fabpot fabpot 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 aba8f1e#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.
1bbc253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/Symfony/Component/ClassLoader/DebugClassLoader.php
View
4 src/Symfony/Component/ClassLoader/DebugClassLoader.php
@@ -84,6 +84,10 @@ public function loadClass($class)
require $file;
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));
}
Something went wrong with that request. Please try again.