Re: [Concept] Flip relative function lookup order (global, then local)

From: Date: Fri, 23 Aug 2024 12:04:22 +0000
Subject: Re: [Concept] Flip relative function lookup order (global, then local)
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-125127@lists.php.net to get a copy of this message
> On Aug 23, 2024, at 7:50 AM, Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk> wrote: > > On Fri, 23 Aug 2024, at 12:29, Mike Schinkel wrote: >> namespace \AcmeComponents\SplineReticulator\Utilities\Text >> >> function Foo():int { >> return Text\strlen("Hello World"); >> } >> >> The above of course could result in BC breaks IF there happened to be >> existing code that referenced Text\strlen() where Text was a top-level >> namespace > > It wouldn't be a top-level namespace that would cause a conflict, but a nested one: > currently the above code resolves the function name as > "AcmeComponents\SplineReticulator\Utilities\Text\Text\strlen" (note the > "...\Text\Text\..."). How often does that really occur in the wild? And how can it occur without an explicit use AcmeComponents\SplineReticulator\Utilities\Text\Text statement, which I proposed would override the automatic use, anyway? > It's an interesting suggestion, but I'm not totally sold on "use the end of the > current namespace" being easier to remember than "use this symbol or keyword". > > return namespace\strlen("Hello World"); # current syntax, rather long and unclear > return _\strlen("Hello World"); # short, but maybe a bit cryptic > return Text\strlen("Hello World"); # variable length, relies on current context > return NS\strlen("Hello World"); # shortening of current keyword > return self\strlen("Hello World"); # maybe confusing to reuse a keyword? > return current\strlen("Hello World"); # clear, but a bit long The only one of those that has a strong analog to existing PHP code is to "use the end of the current namespace" as people frequently do with explicit use statements. Yes, self has a weak analog to self::, but none of the others even come close, IMO. And adding self\ may have unintended to the language, some slight BC concerns, and/or downstream consequences for other projects vs. a simple automatic use. Lastly, no comment on \\? -Mike

« previous php.internals (#125127) next »