Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/Resolver/DeclarationSymbolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ protected function parseUse(Node\Stmt\Use_ $v2): void
if ($type === Node\Stmt\Use_::TYPE_FUNCTION) {
$this->useFunctions[$alias] = $id;
} elseif ($type === Node\Stmt\Use_::TYPE_CONSTANT) {
$lastIndex = strrpos($id, '\\');
$cn = substr($id, $lastIndex + 1);
$ns = substr($id, 0, $lastIndex);
$fullName = $ns . '\\' . $cn;
$this->useConstants[$alias] = $fullName;
// $id is already the fully qualified constant name. Splitting
// and re-joining it on `\` corrupted single-segment imports:
// `use const PHP_EOL;` resolved to `\HP_EOL` because
// strrpos() returns false when there is no separator.
$this->useConstants[$alias] = $id;
} else {
$idLower = strtolower($id);
if ($idLower === 'native_types') {
Expand Down
28 changes: 28 additions & 0 deletions tests/compiler/namespace/use-const-single-segment.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
use const with a single-segment (global) constant name
--FILE--
<?php
namespace App {
use const PHP_EOL;

const ANSWER = 42;

function hello(): string
{
return "hello" . PHP_EOL;
}
}

namespace {
use const App\ANSWER;

function main(): void
{
echo \App\hello();
echo ANSWER, "\n";
}
}
?>
--EXPECT--
hello
42
Loading