Skip to content

Commit a336f0e

Browse files
committed
Skip ::class constant
1 parent 633d0d8 commit a336f0e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ private static function findClasses($path)
118118
case T_CLASS:
119119
case T_INTERFACE:
120120
case SYMFONY_TRAIT:
121+
// Skip usage of ::class constant
122+
$isClassConstant = false;
123+
for ($j = $i - 1; $j > 0; --$j) {
124+
if (is_string($tokens[$j])) {
125+
break;
126+
}
127+
128+
if (T_DOUBLE_COLON === $tokens[$j][0]) {
129+
$isClassConstant = true;
130+
break;
131+
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
132+
break;
133+
}
134+
}
135+
136+
if ($isClassConstant) {
137+
continue;
138+
}
139+
121140
// Find the classname
122141
while (($t = $tokens[++$i]) && is_array($t)) {
123142
if (T_STRING === $t[0]) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function clean($file)
4747
/**
4848
* @dataProvider getTestCreateMapTests
4949
*/
50-
public function testDump($directory, $expected)
50+
public function testDump($directory)
5151
{
5252
$this->prepare_workspace();
5353

@@ -115,6 +115,12 @@ public function getTestCreateMapTests()
115115
));
116116
}
117117

118+
if (PHP_VERSION_ID >= 50500) {
119+
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
120+
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
121+
));
122+
}
123+
118124
return $data;
119125
}
120126

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace ClassCons;
4+
5+
class Foo
6+
{
7+
public function __construct()
8+
{
9+
\Foo\TBar/* foo */::class;
10+
}
11+
}

0 commit comments

Comments
 (0)