Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108269 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42755 invoked from network); 27 Jan 2020 16:48:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jan 2020 16:48:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7E0501804F3 for ; Mon, 27 Jan 2020 06:58:14 -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-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 ; Mon, 27 Jan 2020 06:58:13 -0800 (PST) Received: by mail-lf1-f45.google.com with SMTP id 203so6389237lfa.12 for ; Mon, 27 Jan 2020 06:58:13 -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=4CowoY0Yj1OyCN06ZOCxugGRjZaibbbT8N1n/2IPu1M=; b=nA/dJPuwqC4b4WtcBfR41TXQKyZTJpWDXjA0cYY73sSv8qx2qOqE9ODYksClJr1fam T7MzZHX69J9WtD2Ew/syZSg6joD8zAnsbAhmfEu8na/kbfMuYrAoC09KGii6doexlxjT qkSvFvP6ouZTkC7vpEfVtXBlJ+YpqgxkqPdQOCTAW6IGKBtc9ABiyCH3/owp3tWpBhzu JVxA0M+25UO47CLMK5g10AdBS+cu/BP//IU2hEYuZ71WsnilXiSzJktTFhrYIclnyaZJ rZT9ZiRsDZ8nS8p1dZnuZtjPKhjUJ58+rHo8kgS/RMqHgYFepMDzPHfOSALa0IQiU4HG q9qQ== 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=4CowoY0Yj1OyCN06ZOCxugGRjZaibbbT8N1n/2IPu1M=; b=iphude6BsZZc8jBbt4IRXSeCxWe5j20I4u75avxv0hzmTFnSDV4wMF6MBSqJ1+KP31 +aKoF4JuiRvJIsRHtQZMh+vD7nKqujUm9lsrP4l4HxYkH6301NrrTFsftMislcm3qD2S oULCGl1q/+u0siYTl4tQKkgAo0x4zkbd54z/81uVQyAkGbRZab4SJxvD8q6VIjZwFyL/ zsry50e3kCGwVU+3Nt+iGTtZyjug7oGP+8ZHn7+NPTDOXt4YU54ONvp2TBYqX9jmUflb k1D2YtnnBXK4dQ+ZTTRzi05XaJnLGoDFxPnXkRiDony7QX7eOjA13uBMemLB6/5s2Mb/ tDwA== X-Gm-Message-State: APjAAAWGRS5pofepq8yRL2woVgWdIsG5N1dE/agHjwpcNz2ZFRdxKB5L 6i9pf5NEpKQGdLEcgqZ1EhxEeQlFOsg4+0iwL2o= X-Google-Smtp-Source: APXvYqxFjcsctkXOCo60x+jw257iNFJyGr+e+6VO2Z/jkw9CN1Ot/6ioNl7OEXoOyMwe5XdUBf3QJ0zGS4XLx8LupL8= X-Received: by 2002:ac2:5e29:: with SMTP id o9mr8359171lfg.81.1580137091884; Mon, 27 Jan 2020 06:58:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Jan 2020 15:57:55 +0100 Message-ID: To: tyson andre Cc: Claude Pache , Nicolas Grekas , Mark Randall , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="0000000000000ee8c8059d205641" Subject: Re: [PHP-DEV] [RFC] "use global functions/consts" statement From: nikita.ppv@gmail.com (Nikita Popov) --0000000000000ee8c8059d205641 Content-Type: text/plain; charset="UTF-8" On Mon, Jan 27, 2020 at 3:43 PM tyson andre wrote: > > This would be a compile error right now though, because we don't allow > "use"d symbols and declarations to clash. > > As I surprisingly discovered when implementing the RFC, they don't clash. > The PHP interpreter has a special case where it doesn't warn or throw > about the name being in use > if the resolved (namespaced) name in use is the same as the element being > declared. > See https://3v4l.org/RtPKv - the below example works. > > ``` > > namespace NS; > use function NS\foo; > use const NS\BAR; > > function foo() { echo BAR; } > const BAR = 3; > foo(); > ``` > Interesting :) > > While I was the one who originally suggested to allow this kind of code, > > I think it might be better to just unconditionally make it a compile > error, > > and require the use of declare(function_and_const_lookup='default') > > if you want to declare namespaced constants or functions. > >The main motivation for allowing it is interoperability with > namespace-scoped declares, > > but as those don't exist yet (and would still allow a per-file opt-out), > we can delay this issue. > > > > I think that principally, the correct behavior here is to bring the > symbol into scope as it is declared, > > but as you already pointed out, this leads to unclear semantics when > conditional function declarations are involved. > > The subset of code that can be written requiring "use function NS\foo;" > and "use function NS\MY_CONST;" > with function_and_const_lookup='default' is larger than forbidding it > completely, while still avoiding ambiguity. > Right ... well, as the above code isn't a compile-error like I expected, I guess this is fine :) > > As a minor note, rather than using 'default' as one of the values, > > I think it would be better to use 'fallback' to make it robust against a > potential future change of defaults. > > I'd rather have that done when the future change of defaults is being > proposed. > Supporting 'fallback' might cause confusion and extra work if the name > resolution defaults ever change in a different way. > At the point where they do change, we either do or don't want a way to > support the old 'fallback', > but we will want to support the new 'default'. > > Right now, it's deliberately intended to be the same as just leaving the > setting off for that file. Sounds reasonable. Nikita --0000000000000ee8c8059d205641--