Re: Opt-in "use function *;" for skipping check for function/const in alternate namespace
| From: | tyson andre | Date: | Thu, 28 Nov 2019 23:33:51 +0000 |
| Subject: | Re: Opt-in "use function *;" for skipping check for function/const in alternate namespace | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107890@lists.php.net to get a copy of this message | ||
My previous message can be seen at https://news-web.php.net/php.internals/107887
(marc.info seems to show it as base 64 encoded text.)
It links to a PR https://github.com/php/php-src/pull/4951
implementing this
>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.
Good point. My original thinking was that it'd allow
use function Foo\*; to be
used in the future, but:
- With the way namespaces work, using more than one "wildcard" would result in unintuitive
behavior.
(based on what files were loaded at call time, and what the order of the use was.
Also, instead of checking 2 namespaces, php would have to check an arbitrary list of namespaces.
- People new to the language would assume count would keep working
despite adding use function Foo\*; (e.g. seeing that require/print/isset/empty/eval
resemble functions,
and would continue to work)
Also, there's the large difference between PHP and Python/Java.
The functions in the module are known at the time of import for those, but not for "use"
in PHP.
So rethinking it, something non-generic like "use global functions;" would be my
preference.
Initial plan for a voting structure:
1. Whether a way to opt into exclusively checking global functions and constants should exist
2. Whether this should be part of declare(lookup_functions_in_current_namespace=1) or a
"use" statement, if it does exist
3. The preferred "use" syntax, if there is not clear preference ("use global
functions;" or "use function *;" or otherwise)