Skip to content

Avoid collissions with extension names in namespaced code #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
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: 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 {}
Loading