Re: bikeshed: Typed Aliases

From: Date: Sat, 07 Sep 2024 08:35:19 +0000
Subject: Re: bikeshed: Typed Aliases
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Sat, Sep 7, 2024, at 05:17, Juliette Reinders Folmer wrote:
> On 6-9-2024 20:41, Rob Landers wrote:
>> - This RFC expands the "use ... as ..." syntax to allow any type expression on
>> the left side. These aliases are PER FILE and expire once the file is compiled.
>> 
> 
> Explicitly without expressing any opinion about the RFC, I'd just like to remind you that
> use... import statements for classes and such are not actually per file, but per
> namespace and making the use ... statements for types behave differently would be very
> inconsistent and surprising behaviour.
> 
> These are the rules (as far as I know and based on extensive testing from my side):
> * No namespace - use imports apply to whole file.
> * Curly brace scoped namespace - use imports apply only to the code within the
> current namespace scope.
> * Single unscoped namespace - use imports apply to whole file (as the whole file
> is within the single unscope namespace)
> * Multiple unscoped namespaces - use imports apply only until the next namespace
> declaration is encountered.
> 
> Having type use behave differently to other import use statements
> would, I imagine, also bring up problems around "file contains 2 scoped namespaces, type use is
> for the file, but - as things currently are - no code is allowed in the file outside the scoped
> namespaces, so where to place the import for the type ? and what would it then apply to ?"
> 
> Smile,
> Juliette

Thanks Juliette,

I meant "as they are now" and not literally "per file" as described in the RFC.
I will make that more clear in the RFC. When I wrote it, I was thinking in terms of how I usually
write namespaced code and thought of it as "per file" but that is probably the wrong
mental model in any case. Thanks again for pointing this out.

— Rob


Thread (25 messages)

« previous php.internals (#125465) next »