Navigation Menu

Skip to content

Commit

Permalink
bug #15376 [ClassMapGenerator] Skip ::class constant (WouterJ)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

[ClassMapGenerator] Skip ::class constant

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15351
| License       | MIT
| Doc PR        | -

Commits
-------

a336f0e Skip ::class constant
  • Loading branch information
fabpot committed Aug 1, 2015
2 parents 9293c43 + a336f0e commit 3b6d2a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Expand Up @@ -118,6 +118,25 @@ private static function findClasses($path)
case T_CLASS:
case T_INTERFACE:
case SYMFONY_TRAIT:
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (is_string($tokens[$j])) {
break;
}

if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}

if ($isClassConstant) {
continue;
}

// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ private function clean($file)
/**
* @dataProvider getTestCreateMapTests
*/
public function testDump($directory, $expected)
public function testDump($directory)
{
$this->prepare_workspace();

Expand Down Expand Up @@ -115,6 +115,12 @@ public function getTestCreateMapTests()
));
}

if (PHP_VERSION_ID >= 50500) {
$data[] = array(__DIR__.'/Fixtures/php5.5', array(
'ClassCons\\Foo' => __DIR__.'/Fixtures/php5.5/class_cons.php',
));
}

return $data;
}

Expand Down
@@ -0,0 +1,11 @@
<?php

namespace ClassCons;

class Foo
{
public function __construct()
{
\Foo\TBar/* foo */::class;
}
}

0 comments on commit 3b6d2a3

Please sign in to comment.