Skip to content

Reserve same-namespace short names during import#13

Merged
ruudk merged 1 commit intomainfrom
fix
Apr 18, 2026
Merged

Reserve same-namespace short names during import#13
ruudk merged 1 commit intomainfrom
fix

Conversation

@ruudk
Copy link
Copy Markdown
Owner

@ruudk ruudk commented Apr 18, 2026

When a class is imported with the same namespace as the current file, its short name is now recorded as a reserved alias rather than silently returned. Without the reservation, a later import from a different namespace with the same short name was also returned unaliased, so the generated file ended up with use X\Y\Foo; alongside a class Foo declaration — which PHP rejects as a redeclaration.

findAvailableAlias already bumps colliding entries to Foo2, so recording the reservation is enough to make conflicting external imports flow through that path automatically.

When a class is imported with the same namespace as the current file,
its short name is now recorded as a reserved alias rather than silently
returned. Without the reservation, a later import from a different
namespace with the same short name was also returned unaliased, so the
generated file ended up with `use X\Y\Foo;` alongside a `class Foo`
declaration — which PHP rejects as a redeclaration.

`findAvailableAlias` already bumps colliding entries to `Foo2`, so
recording the reservation is enough to make conflicting external
imports flow through that path automatically.
@ruudk ruudk merged commit 6386151 into main Apr 18, 2026
1 check passed
@ruudk ruudk deleted the fix branch April 18, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant