Re: Opt-in "use function *;" for skipping check for function/const in alternate namespace
| From: | Claude Pache | Date: | Thu, 28 Nov 2019 13:19:00 +0000 |
| Subject: | Re: Opt-in "use function *;" for skipping check for function/const in alternate namespace | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107884@lists.php.net to get a copy of this message | ||
> Le 28 nov. 2019 à 12:56, Rowan Tommins <rowan.collins@gmail.com> a écrit :
>
> On Thu, 28 Nov 2019 at 11:01, Claude Pache <claude.pache@gmail.com> wrote:
>> I think it is better to keep the language as regular as possible, and
> consider that every non-fully-qualified name is relative to the current
> namespace, unless there is an explicit
use declaration that
> says otherwise
>
> That's already false, and will only be true if we deprecate and remove the
> fallback to global scope.
>
>
>> use function *; // don't know what this does, but apparently it's good for
>>> performance ¯\_(ツ)_/¯
>>
>> Or: “don't know what this does, but apparently it silences deprecation
>> notices...”
>>
>
>
> Silencing deprecation notices is always a temporary side-effect of fixing
> code to work *at all* in some future release. Or rather, it should be - I
> am 100% against any notion of "indefinitely deprecated and may never be
> removed", that should always be some other type of notice.
>
> If we were deprecating unqualified functions from being looked up in the
> current namespace, we would not need to add this new directive, we could
> raise deprecation notices whenever the current lookup logic succeeded in
> finding a namespaced function. Silencing the deprecation notice would
> require either fully qualifying the function name, or explicitly adding a
> "use" statement.
>
>
>
> The issue indeed is that the meaning is far from self-evident. Maybe one
>> could use something that everyone and their mother could understand at
>> first reading, such as:
>>
>> use function from global namespace;
>>
>
>
> That still doesn't really explain what's happening, because in code that
> doesn't use any namespaced functions, the line has no user-visible effect
> at all - functions are *always* used from the global namespace. What it
> actually does is switch *off* a language feature, so perhaps it should be
> something more like:
>
> declare(lookup_functions_in_current_namespace=false);
>
> That would also mean that it can be covered by any future way of setting
> language directives, such as settings per "module", bundling into
> "editions", etc.
>
> Regards,
> --
> Rowan Tommins
> [IMSoP]
I wasn’t clear enough in my previous post: I was assuming that the ultimate goal was to remove
(after deprecation) the fallback to global namespace. In that regard, the use function
* declaration (or whatever variation of that) is both a way to programmer to say the
preferred semantics regarding not-fully-qualified function names, and a tool to let most legacy
scripts survive without too much effort.
But probably I made a too strong assumption about the intended goal of the proposed feature?
—Claude