Skip to content

Commit

Permalink
Avoid collissions with extension names in namespaced code (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Nov 18, 2024
1 parent bc01976 commit 0acd9d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/UsedSymbolExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public function parseUsedSymbols(
} elseif (isset($extensionSymbols[$lowerName])) {
$symbolName = $name;
$kind = $extensionSymbols[$lowerName];

if (!$inGlobalScope && $kind === SymbolKind::CLASSLIKE) {
break; // cannot use class-like symbols in non-global scope when not imported
}

$usedSymbols[$kind][$symbolName][] = $token[2];
}

Expand Down Expand Up @@ -211,6 +216,11 @@ public function parseUsedSymbols(
} elseif (isset($extensionSymbols[$lowerName])) {
$symbolName = $name;
$kind = $extensionSymbols[$lowerName];

if (!$inGlobalScope && $kind === SymbolKind::CLASSLIKE) {
break; // cannot use class-like symbols in non-global scope when not imported
}

$usedSymbols[$kind][$symbolName][] = $token[2];

} else {
Expand Down
4 changes: 3 additions & 1 deletion tests/data/not-autoloaded/used-symbols/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use { DDTrace, DDTrace\Integrations };
use function DDTrace\active_span;
use My\App\XMLReader;
use My\App\XMLReader, PDO;

json_encode('');
LIBXML_ERR_FATAL;
Expand All @@ -23,3 +23,5 @@

function foo($normalizer) {}
foo(normalizer: 1);

class Normalizer {}

0 comments on commit 0acd9d9

Please sign in to comment.