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

From: Date: Sun, 04 Aug 2024 17:41:17 +0000
Subject: Re: [Concept] Flip relative function lookup order (global, then local)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-124742@lists.php.net to get a copy of this message
Hi Rob On Fri, Aug 2, 2024 at 7:10 PM Rob Landers <rob@bottled.codes> wrote: > > So, what you’re saying is that symfony and laravel can get a performance increase by simply > adding a \ in the right places? Why don’t they do that instead of changing the language? Nothing, of course. However, a Symfony maintainer has expressed uninterest in prefixing all internal function calls, including automated use statements at the top of the file. Even if they did, most users will not. > For functions/classes in the same exact namespace, you don’t need a use statement. But after > this change, you do in certain cases? > > namespace Foo; > > function array_sum($bar) {} > > function baz($bar) { > return array_sum($bar); > } > > So, how do you use that function in the same file? Yes. But I'm not sure how that's different from today? If there's a local and global function declared with the same name, and you intend to call the global one, you'll already need to disambiguate the call with a \. With this change, your two options would be to: * Prefix your calls with namespace\. That's quite ugly, but is the syntax we currently offer. * Add a use array_sum; to the top of the file. An explicit use has upsides too. It makes it much more obvious that the global function is shadowed. > We can only see open source code when doing impact analysis. This means picking even a slightly > “popular” name could go very poorly. Yes, and there are many more than 10 000 composer repositories. An impact analysis can give you an approximation for breakage, not absolute numbers. Ilija

« previous php.internals (#124742) next »