Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

fix #6814: ignore php 5.5 scalar class name resolution #6946

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions library/Zend/File/ClassFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public function accept()
break;
case $t_trait:
case T_CLASS:
// ignore T_CLASS after T_DOUBLE_COLON to allow PHP >=5.5 FQCN scalar resolution
if ($i > 0 && is_array($tokens[$i-1]) && $tokens[$i-1][0] === T_DOUBLE_COLON) {
break;
}
case T_INTERFACE:
// Abstract class, class, interface or trait found

Expand Down
15 changes: 15 additions & 0 deletions tests/ZendTest/File/ClassFileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,19 @@ public function testIterationShouldFindMultipleClassesInMultipleNamespacesInSing
$this->assertTrue($foundThird);
$this->assertTrue($foundFourth);
}

public function testIterationShouldNotCountFQCNScalarResolutionConstantAsClass()
{
if (version_compare(PHP_VERSION, "5.5", "<")) {
$this->markTestSkipped('Only applies to PHP >=5.5');
}

$locator = new ClassFileLocator(__DIR__ .'/TestAsset');
foreach ($locator as $file) {
if (! preg_match('/ClassNameResolutionCompatibility\.php$/', $file->getFilename())) {
continue;
}
$this->assertCount(1, $file->getClasses());
}
}
}
20 changes: 20 additions & 0 deletions tests/ZendTest/File/TestAsset/ClassNameResolutionCompatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\File\TestAsset;

use stdClass;

class ClassNameResolutionCompatibility
{
protected $someClassNames = [
stdClass::class,
stdClass::class,
];
}