Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108228 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13388 invoked from network); 24 Jan 2020 17:50:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jan 2020 17:50:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0713118059E for ; Fri, 24 Jan 2020 08:00:25 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 24 Jan 2020 08:00:24 -0800 (PST) Received: by mail-lj1-f179.google.com with SMTP id n18so3040151ljo.7 for ; Fri, 24 Jan 2020 08:00:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D38rlee1BsRbEYfSuj7Dd8QhJKRWFuLKdQIqm4clrEc=; b=Rrlb63+1+gP5PKEboqnTzjDVCh/YY3HrFM8ReF5eiteryoo7rornFkJqNKIsDrUvm7 dQd2oKzVSjfyomcsuPR61xgnpSDKXciNRnW+ug2Tq1+c4GBb8k8xorXk6lSllK3YQGxz gF9vXTdXbbKrmP78RY1NRx2ZXLgLm/jl2dRrPPS7LjMGM0RKoIPlr8HrLJwFBTvAjU3Y UtAzD7yUqRID17ihTnMGrko63WtONChKnMNz7CnsPV1nw+kH5oy/Wgi3Ym2BHQzWfIf0 X95+pzTHMI3AX5EpWSxn0Xmb9z6//AF/f+3WijS5ei/ARbB7TYPytwKsInyxm+EeQHoi okCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D38rlee1BsRbEYfSuj7Dd8QhJKRWFuLKdQIqm4clrEc=; b=UJoQ/ft42oLrO9nFApQFt9CyBhGtoqMNKt+a2zLW2MWZQiHgYgh3K3w9d2YY0v5auy J0yU7OdYQwFCCPeKx7MzzFVsrb4z9TIlFiPIWPNcy0o55i1uTbMmcA91pjPdt5yYyUd0 WEoOZnmB4/yE9M4INigR/07IcjBLoXOXv7+Fr+p4hMDSzFSsroe+KKoOzrlO9R9Xw98R Zb8GaOjWyWP6eVM8TvwTBJ0jmpIb5lQIwH0KFtW3qSqWPNonzB9fCaxDrbPXg7W4ZK3I vJQ9E85MLz9lHiR6Ml0IqOwZdiWKrYWYawel/l3wT67F5BTpAimW8Iy5vJAoWrWGfoYl W+gg== X-Gm-Message-State: APjAAAXhb2L0jaXuiGD8nv6qJfZ8AFYniWgXsfzRo06BTMYHcPQmxAq8 vDrR/du2lY5y7/TTuo37bOqO9SnLrdLegzRYQHo= X-Google-Smtp-Source: APXvYqz66SDf/0O5oZsR3G6FZB7hpZ3lu2zD2BEPogdyf4+q9JLPY6GAZaltkJfRMeZ6ys94OPGVGPjR899a0TJhNoQ= X-Received: by 2002:a2e:b55c:: with SMTP id a28mr2608591ljn.260.1579881622416; Fri, 24 Jan 2020 08:00:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 24 Jan 2020 17:00:06 +0100 Message-ID: To: tyson andre Cc: Mark Randall , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000e432e7059ce4da59" Subject: Re: [PHP-DEV] Re: [RFC] "use global functions/consts" statement From: nikita.ppv@gmail.com (Nikita Popov) --000000000000e432e7059ce4da59 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 18, 2020 at 11:53 PM tyson andre wrote: > > I'd much rather have something like: > > > > declare(ambiguous_element_lookup=3D0) > > > > declare(ambiguous_element_lookup=3Doff) > > Aside: declare(unambiguous_element_lookup=3D1) is probably a better choic= e > than my first choice of (disable_ambiguous_element_lookup=3D1), but proba= bly > not the best choice. > > > I find that the =E2=80=9Cdisable_ambiguous_element_lookup=E2=80=9D dire= ctive name is, > well, ambiguous. > > Does it mean that it will look up only in the current namespace, or onl= y > in the global namespace? I can=E2=80=99t guess. > > > > Maybe a three-value directive: > > > > declare(function_and_const_lookup=3Dglobal); > > declare(function_and_const_lookup=3Dnamespace); > > declare(function_and_const_lookup=3Dfallback); // the default > > That's my favorite setting name overall so far - it ends up being as long > as disable_ambiguous_element_lookup and more self-explanatory. > I don't plan to include namespace-only in the RFC - future RFCs could > propose additional values independently. > > Probably just `=3D global` and `=3D default`, because the default might > eventually change (from the fallback), > and =3D fallback could be added if the old fallback was desirable enough. > - `=3D default` would only be useful to set resolution back to the defaul= t > with future language changes such as > https://wiki.php.net/rfc/namespace_scoped_declares#implementation_conside= rations > It looks like the implementation has been updated to the style proposed here, while the RFC still uses disable_ambiguous_element_lookup. I like the idea of using a meaningful value here, but think that this should be using a string, i.e. declare(function_and_const_lookup=3D'global'= ) rather than declare(function_and_const_lookup=3Dglobal). Currently declare(= ) syntax uses a normal constant expression on the right hand side of the =3D, and I don't see a strong reason why we should deviate from that for this feature. An existing declare using a string is declare(encoding=3D'UTF-8'). The RFC says: function sprintf($msg, ...$args) { // this and remaining statements still refer to \sprintf, not MyNS\sprintf return sprintf("Prefix $msg", ...$args); } This looks a bit peculiar... We could also say that declaring a symbol also automatically brings it into scope. I'm not really sure which is better. As a general note on the overall proposal: I think this is a very pragmatic proposal. It addresses a real issue, and it addresses it in the most straightforward way. You can just drop the declare in your code, and it will keep working exactly as it did before, just faster. Assuming you weren't doing anything stupid, of course. The big downside is that this makes class and function symbol resolution complete opposites. Classes only look in the current namespace. Functions only look in the global namespace. This reflects the way they are most commonly used, but is not a great place to end up from a language design perspective. There are two alternatives that keep class and function symbol resolution the same: One is to always only look in the namespace. This has been suggested a few times in the past, including in this thread, and the RFC https://wiki.php.net/rfc/fallback-to-root-scope-deprecation. I think this is a fairly unpopular option, because using fully qualified names for functions tends to be quite ugly (more so than for classes, due to the positions they're used in), or requires a large number of imports, as even a small piece of code can easily use a dozen different string/array functions. One option that I haven't seem much discussion on is the opposite: Always only look in the global namespace. Any unimported unqualified usages will be treated as fully qualified names. This would match the proposed semantics for functions/consts and change the resolution rules for classes. I think this would have relatively little impact on how code is written, as classes already tend to make extensive use of cross-namespace references and the import is usually IDE managed. Regards, Nikita --000000000000e432e7059ce4da59--