Skip to content
This repository

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

Closed
wants to merge 1 commit into from

2 participants

Christophe Coevoet Fabien Potencier
Christophe Coevoet
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.

Fabien Potencier fabpot referenced this pull request from a commit January 19, 2013
Fabien Potencier 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
Fabien Potencier fabpot closed this January 21, 2013
Christophe Coevoet stof deleted the branch January 21, 2013
mmucklo mmucklo referenced this pull request from a commit January 19, 2013
Fabien Potencier 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

Showing 1 unique commit by 1 author.

Jan 18, 2013
Christophe Coevoet Added an error message in the DebugClassLoader when using / instead o…
…f \.
be05741
This page is out of date. Refresh to see the latest.
4  src/Symfony/Component/ClassLoader/DebugClassLoader.php
@@ -84,6 +84,10 @@ public function loadClass($class)
84 84
             require $file;
85 85
 
86 86
             if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
  87
+                if (false !== strpos($class, '/')) {
  88
+                    throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".'));
  89
+                }
  90
+
87 91
                 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));
88 92
             }
89 93
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.