Skip to content

Commit 27327d3

Browse files
committed
bug #16668 [ClassLoader] Fix parsing namespace when token_get_all() is missing (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [ClassLoader] Fix parsing namespace when token_get_all() is missing | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14871 | License | MIT | Doc PR | - Commits ------- 4a17c9e [ClassLoader] Fix parsing namespace when token_get_all() is missing
2 parents bece73a + 4a17c9e commit 27327d3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
137137
public static function fixNamespaceDeclarations($source)
138138
{
139139
if (!function_exists('token_get_all') || !self::$useTokenizer) {
140-
if (preg_match('/namespace(.*?)\s*;/', $source)) {
141-
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
140+
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
141+
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
142142
}
143143

144144
return $source;

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function getFixNamespaceDeclarationsDataWithoutTokenizer()
205205
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
206206
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
207207
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
208-
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
208+
array("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
209209
);
210210
}
211211

0 commit comments

Comments
 (0)