Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108261 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77306 invoked from network); 27 Jan 2020 11:21:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jan 2020 11:21:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D829F180504 for ; Mon, 27 Jan 2020 01:31:34 -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,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-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 01:31:34 -0800 (PST) Received: by mail-lj1-f181.google.com with SMTP id a13so9832578ljm.10 for ; Mon, 27 Jan 2020 01:31:34 -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=1mk7+r6p70iVjmFzYd6xiSPIIULb1AI1RnAA2Uckjt4=; b=XdCuE+K1gptwJyo/8LbglIdDolqTq7L71UZzbzGYZoER6qtuN1njgFD+NsgaFE9720 41sLFDAlRROt0AA5Vr6Kr05Kp04X9DaCdXTMi8OCdZGYJJlfps76tBk5JAjXfE6Ykqfz dm1brnAA/HxLRdZ7eXbySMfNwClmStnSEFL0qVPjk1poCQbTv+pzt6UUWhcqcN8DcAKz uMRi5qSNEf5FXIm7JepLUwAoi2ESnpPTguwnsSUCRAaWnRxltTlDu2aVUvMuOMlUZJHO 68/Iayq9WX2qHi1Ivcj3wWInresJAdWxQiJ+tAdauow48E5AJ3iE+YytUdRvRn5Rvezq ATlg== 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=1mk7+r6p70iVjmFzYd6xiSPIIULb1AI1RnAA2Uckjt4=; b=JU/EOsnzBTa2ICjnlAJc6zAjWpxqaG0heW3Z9T5ZVi39Node7OwCME5c0TWnjvvLt1 Ea6fuKCMwSgHCb7ZErE3EhKIzYCczaTDpoiQ1Gb4SpWPG6AFIKnjvFo9e3kPVx3yaLTe 1Synwntc/Pt60Kch9+46RF4mS+lfiTgUxwTe1yUgOGkjsMD2cIfQlTaWo4oUWBnE3qjM zN82PivJQh9NrOYd1QP/Frh5VDAJWV5EUhLApMdpK6bA7oEcaQ5MNu7HKjSVAtLacsu/ qTP+4Q1yKkIbTlgVX2huQhoB6CdyM/tq3S7/O8Cb2gURDf5hbtVP3KS2TBV+EPR/x+uI a/vg== X-Gm-Message-State: APjAAAUQ9JNUXK2PVH58Lwm5TvDkO0mX2dNsPzMcr4PdIanoAOJZWhRb m1TLoPFw3Kfaq5CEvfJfoIXCGaMmbhKqNZRgrSQ= X-Google-Smtp-Source: APXvYqzkE0Id0FEHt5zWF1LVt1i4hhwmIlLUe+jphMRzaJwxts2CzFt+RJD8TXzokAzuT5gZT9qOuVwOuFAJX1h1s/w= X-Received: by 2002:a2e:924d:: with SMTP id v13mr9917641ljg.267.1580117493342; Mon, 27 Jan 2020 01:31:33 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Jan 2020 10:31:16 +0100 Message-ID: To: tyson andre Cc: Claude Pache , Nicolas Grekas , Mark Randall , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000e4e64e059d1bc5fb" Subject: Re: [PHP-DEV] [RFC] "use global functions/consts" statement From: nikita.ppv@gmail.com (Nikita Popov) --000000000000e4e64e059d1bc5fb Content-Type: text/plain; charset="UTF-8" On Sun, Jan 26, 2020 at 10:37 PM tyson andre wrote: > > and that you have to explicitly say that you use the current namespace > for that name: > > > > > declare(function_and_const_lookup='global'); > > namespace MyNS; > > use function MyNS\foo; > > // or, equivalently: use function namespace\foo: > > > > function foo() { } > > > > foo(); // <-- this is the function defined just above > This would be a compile error right now though, because we don't allow "use"d symbols and declarations to clash. > That's a good solution to the ambiguity that I hadn't considered. > Functions and constants should be relatively uncommon for most projects, > although I can see it getting repetitive for a file with dozens of > constants. > (e.g. with namespace-scoped declares) > define() or declare(function_and_const_lookup='global') should be adequate > workarounds. > - A subsequent RFC could reduce the restriction and make "const X = ..." > always act as though it was immediately preceded by "use const X" > This works better for constants than functions because constants can't > be declared anywhere but the top level. 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. 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. Regards, Nikita --000000000000e4e64e059d1bc5fb--