On Fri, Aug 23, 2024, at 09:27, Nick Lockheart wrote:
> On Fri, 2024-08-23 at 07:39 +0100, Rowan Tommins [IMSoP] wrote:
> > 
> > 
> > On 23 August 2024 00:15:19 BST, Mike Schinkel <m...@newclarity.net>
> > wrote:
> > > Having to prefix with a name like Foo, e.g. Foo\strlen() is FAR
> > > PREFERABLE to _\strlen() because at least it provides satiating
> > > information rather than the empty calories of a cryptic shorthand. 
> > > #jmtcw, anyway.
> > 
> > I knew I'd regret keeping the example short. Realistically, it's not
> > a substitute for "\Foo\strlen", it's a substitute for
> > "\AcmeComponents\SplineReticulator\Utilities\Text\strlen".
> > 
> > Having a syntax for "relative to current" is incredibly common in
> > other path-like syntaxes. The most common marker is ".", and ".\foo"
> > is literally how you'd refer to something in the current directory
> > under DOS/Windows. But unfortunately, we don't have "." available, so
> > I wondered if "_" would feel similar enough.
> > 
> > Another option would be to find a shorter keyword than "namespace" to
> > put it in front. "ns\strlen(...)" is an obvious step from what we
> > have currently, but it's not very obvious what it means, so maybe
> > there's a different word we could use.
> > 
> > Rowan Tommins
> > [IMSoP]
> 
> Could be mistaken, but I think the way PHP handles namespaces
> internally is sort of the same as a long string, rather than as a
> tree/hierarchy.
> 
> ie. \AcmeComponents\SplineReticulator\Utilities\Text\strlen
> 
> is really like:
> 
> class AcmeComponentsSplineReticulatorUtilitiesTextstrlen {
> 
>    public function __construct(){
> 
>    }
> 
> }
> 
> And the "AcmeComponentsSplineReticulatorUtilitiesText" just kind of
> gets appended to the front when the class name is registered.
> 
> I haven't done work on the namespace code, but I recall reading this
> somewhere recently.

This is mostly correct, the only thing missing from your strings is the `\` 
character. I believe this even happens during compilation. Meaning it sees your 
namespace/uses and then rewrites the function/class calls during compile time. 
Thus an unqualified call is prepended with the current namespace defined at the 
top of the file.

If we were to go with any major change in the current lookup where it is perf 
or nothing, this is what I would propose for php 9.0 (starting with an 
immediate deprecation):
 1. any unqualified call simply calls the current namespace
 2. >= php 9.0: no fallback to global
 3. < php 9.0: emit deprecation notice if falls back to global
This is how classes work (pretty sure), so it would be consistent.

Going the other way (global first) doesn't really make sense because it is 
inconsistent, IMHO. Will it suck? Probably. Will it be easy to fix? Probably 
via Rector.

— Rob

Reply via email to