Skip to content

Commit 0acd9d9

Browse files
authored
Avoid collissions with extension names in namespaced code (#199)
1 parent bc01976 commit 0acd9d9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/UsedSymbolExtractor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public function parseUsedSymbols(
163163
} elseif (isset($extensionSymbols[$lowerName])) {
164164
$symbolName = $name;
165165
$kind = $extensionSymbols[$lowerName];
166+
167+
if (!$inGlobalScope && $kind === SymbolKind::CLASSLIKE) {
168+
break; // cannot use class-like symbols in non-global scope when not imported
169+
}
170+
166171
$usedSymbols[$kind][$symbolName][] = $token[2];
167172
}
168173

@@ -211,6 +216,11 @@ public function parseUsedSymbols(
211216
} elseif (isset($extensionSymbols[$lowerName])) {
212217
$symbolName = $name;
213218
$kind = $extensionSymbols[$lowerName];
219+
220+
if (!$inGlobalScope && $kind === SymbolKind::CLASSLIKE) {
221+
break; // cannot use class-like symbols in non-global scope when not imported
222+
}
223+
214224
$usedSymbols[$kind][$symbolName][] = $token[2];
215225

216226
} else {

tests/data/not-autoloaded/used-symbols/extensions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use { DDTrace, DDTrace\Integrations };
55
use function DDTrace\active_span;
6-
use My\App\XMLReader;
6+
use My\App\XMLReader, PDO;
77

88
json_encode('');
99
LIBXML_ERR_FATAL;
@@ -23,3 +23,5 @@
2323

2424
function foo($normalizer) {}
2525
foo(normalizer: 1);
26+
27+
class Normalizer {}

0 commit comments

Comments
 (0)