On 04/08/2024 18:41, Ilija Tovilo wrote:
* Prefix your calls with namespace\. That's quite ugly, but is the
syntax we currently offer.
I was thinking about this earlier, and how the migration is pretty much
the same (and equally automatable) in either direction:
* If unqualified calls become always local, then every global function
call needs a use statement or prefixing with "\".
* If they become always global, then every local function call needs a
use statement or prefixing with "namespace\".
But the first option probably requires changes in the majority of PHP
files in use anywhere; whereas the second only affects a small minority
of code bases, and a small minority of code in those.
BUT, if people already complain about "\" being ugly, having to write
"namespace\" is going to make them REALLY grumpy...
So maybe at the same time (or, probably, in advance) we need to come up
with a nicer syntax for explicitly referencing the current namespace.
Unfortunately, finding unused syntax is hard, which is why we have "\"
in the first place (and for the record, I think it works just fine), but
maybe something like "_\" could work? Giving us:
namespace Foo;
$native_length = strlen('hello'); # same as \strlen('hello')
$foo_length = _\strlen('hello'); # same as \Foo\strlen('hello')
If I had a time machine, I'd campaign for "unqualified means local" in
PHP 5.3, and we'd all be used to writing "\strlen" by now; but
"unqualified means global" feels much more achievable from where we are.
--
Rowan Tommins
[IMSoP]