Skip to content

Commit aef93dc

Browse files
committed
[ClassLoader] Fix ClassCollectionLoader inlining with __halt_compiler
1 parent 40dc73a commit aef93dc

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
106106

107107
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
108108
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
109+
$haltCompilerRegex = str_replace('.', $c, "'.__halt_compiler.\(.\).'is");
109110

110111
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
111112
$files = array();
@@ -118,7 +119,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
118119
$files[] = $file = $class->getFileName();
119120
$c = file_get_contents($file);
120121

121-
if (preg_match($strictTypesRegex, $c)) {
122+
if (preg_match($strictTypesRegex, $c) || preg_match($haltCompilerRegex, $c)) {
122123
$file = explode(DIRECTORY_SEPARATOR, $file);
123124

124125
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testCommentStripping()
235235
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
236236

237237
ClassCollectionLoader::load(
238-
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
238+
array('Namespaced\\WithComments', 'Pearlike_WithComments', 'Namespaced\\WithHaltCompiler', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
239239
__DIR__,
240240
'bar',
241241
false
@@ -275,6 +275,7 @@ class Pearlike_WithComments
275275
public static $loaded = true;
276276
}
277277
}
278+
namespace {require __DIR__.'/Fixtures/Namespaced/WithHaltCompiler.php';}
278279
EOF
279280
.$strictTypes,
280281
str_replace(array("<?php \n", '\\\\'), array('', '/'), file_get_contents($file))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* foo
5+
*/
6+
7+
namespace Namespaced;
8+
9+
class WithHaltCompiler
10+
{
11+
}
12+
13+
// the end of the script execution
14+
__halt_compiler(); data
15+
data
16+
data
17+
data
18+
...

0 commit comments

Comments
 (0)