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

From: Date: Fri, 23 Aug 2024 08:08:25 +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-125109@lists.php.net to get a copy of this message
> > 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 A third option, which I haven't seen come up on the list yet, is that unqualified functions that are PHP built-ins are treated as global, and using a function having the same name as a built-in, in a namespace scope, requires a fully qualified name to override the built-in. It seems that if someone is writing array_key_exists() or similar they probably mean the built-in function, and in the rare cases where they do mean \foo\array_key_exists(), they can write it explicitly. Functions that are *not* on the built-in function list could default to the local namespace.

« previous php.internals (#125109) next »