On 28/11/2019 18:52, tyson andre wrote:
An opt-in mechanism is certainly easier to migrate to, but it would be a
shame if every PHP file in 10 years time included a line like this:

use function *; // don't know what this does,
but apparently it's good for performance ¯\_(ツ)_/¯
I'm not sure what assumptions you're making about php in 10 years
(e.g. do you assume the other RFC will pass and this would become a no-op)


My assumptions weren't particularly about the future of PHP, but about people's usage patterns. If nobody uses namespaced functions, then everyone will just turn on this option all the time, without ever needing to know what it does. The effect of adding it to 99% of PHP files would be nothing but a "magical" performance boost.


if someone were to fully qualify all function calls for a library for 
performance,
there'd be around 10 lines per file instead of 1

Only if they did it by adding use statements, rather than prefixing the function calls with backslashes. I'm confused why anyone would bother keeping a long list of use statements up to date, rather than just making "use leading backslashes on global functions" part of the project's coding style. I can see that adding a single statement to each file would be better than either, though.


My reasons for this syntax instead of that are:

- This syntax can go in one block of code, instead of separated by dozens of 
lines:

   <?php declare(strict_types=1);
   // dozens of lines of class uses, file comments, etc.
   use function otherns\my_function;
   use function *;
- There are no per-namespace declare() directives right now, for code with 
multiple namespace blocks

I think it's more than just a different choice of syntax, it's a different way of looking at the feature: rather than a special namespace import, it's an option for how the language behaves. My thinking is that if unprefixed functions *always* referred to the global namespace, we wouldn't say "the global namespace is imported by default", we'd just describe the behaviour.

Looked at from that perspective, it seems natural to say "in this file, I want the behaviour where unprefixed functions mean global by default"; and in future, maybe be able to say "in this entire module, I want that behaviour".


A more cosmetic consideration is that the more generic the syntax looks, the more people will want it to work for other use cases. I can imagine "use function * works but use Foo\* doesn't" ending up on websites like PHPSadness. A more specific statement, like a declare, or "use global functions", is more obviously a one-off.

Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to