Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108250 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70811 invoked from network); 26 Jan 2020 11:59:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jan 2020 11:59:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EA691804F3 for ; Sun, 26 Jan 2020 02:09:15 -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 ; Sun, 26 Jan 2020 02:09:15 -0800 (PST) Received: by mail-lj1-f181.google.com with SMTP id n18so7519763ljo.7 for ; Sun, 26 Jan 2020 02:09:15 -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=yuPRpxP/SwQfcAF9L1wwbpeLXgDirVF2bSbcjGeQwP0=; b=Yux/45xxGeRcdNJdrD1sgUnyI9Vsp88eR50D4L/O/V7JcAo9iDGPwwTzNRM0KLIwit JaH8HbpAzaNq2nmSd2l5yEF0KecesE/w3qd9WwD2IWyvqNdY4ZtPsIRUYUl4BX0T1Mn7 KxQ4yxLSyxs6AtSSSEIRIE3x+a8JfHixfMHclN8bvwFAibL2Y+c9pGooxyPxkPE3FLsh ce0EeRtC/CsENk2y0d5RTolboUBWuc6OlS16LynMetduD+IoDudZNeM4W4QWqBNwDdb2 X6Bgd3k9qN0PojESjLTGbwkphOm9C0PQqhxIMD8V/zPa0EzA31rV/xPiBoavfHK4nXSD fLCg== 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=yuPRpxP/SwQfcAF9L1wwbpeLXgDirVF2bSbcjGeQwP0=; b=IZXBC++HwROqTDufIo6HouMBjvDjuN25fKcXQxqeq6R/i5GXPwnEeiHLEpDK4y4tXv Kufqd08ytJoIV2pEJiB/ckGGJ0JLbbM80OZ+2ZQZULoaJeytg/67gb2ionVA2wwBg8l8 EC4cp2OF7nuMjOH9xM2zT4tD39XbelwyNcfsFXEkxpSpdAleRU6mW2/EUrfwpnY6WvNW 89UYLmrOXDJ76+xsqndAU/6aYvpEC87AtgUDrOUSD7Pqr2KVRkJASId/lhUXbZio316a ZVTN9sARi0GSGHT3o4anPWg18H1txwqHjRLTATzrF0dKDs+as8lsLdRD99XKHR0eNk9M 1ykQ== X-Gm-Message-State: APjAAAX6nPs/vILDBFEwcKcwUYDWthZYcW/byybfRkjvjHHK94MDOFVO WYn9nUnexhkeCRi04W8CoccCpq++ZLRM4CiTlpY= X-Google-Smtp-Source: APXvYqwNIwyad3ptdhCwl1ld6yLT07uBQiJH/NN2+kTXQFXXKDLSFF1421mcNpR/KqOf+aGUmYJT9itBDqGe4JzMboM= X-Received: by 2002:a2e:2e11:: with SMTP id u17mr6939712lju.117.1580033352707; Sun, 26 Jan 2020 02:09:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 26 Jan 2020 11:08:56 +0100 Message-ID: To: tyson andre Cc: Nicolas Grekas , Mark Randall , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000b8b245059d082e87" Subject: Re: [PHP-DEV] Re: [RFC] "use global functions/consts" statement From: nikita.ppv@gmail.com (Nikita Popov) --000000000000b8b245059d082e87 Content-Type: text/plain; charset="UTF-8" On Fri, Jan 24, 2020 at 6:58 PM tyson andre wrote: > > 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='global') > > rather than declare(function_and_const_lookup=global). Currently > declare() > > syntax uses a normal constant expression on the right hand side of the =, > > 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='UTF-8'). > > Whether it's quoted is a low priority to me - I went with the unquoted > implementation > because it might be something repeated in every file of a project, > and it'd be slightly more convenient to avoid quotes and use keywords if > there were > many more settings with different values (=on, =off, =warning, etc) in the > future. > A difference is that it makes sense to quote encodings such as UTF-8 > because of the '-', > but not as much to quote keywords without special characters. > Saving two characters per file doesn't seem like a great motivation to add additional special cases to core language syntax. Right now, declare just types "identifier = expr", while with this change it's going to be "identifier = (expr | a | few | extra | keywords)". > > 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. > > It's fairly common for NS\SubNS\ClassName to mention other classes from NS\SubNS\OtherClassName right now, > (more commonly than use Exception, use Throwable, etc in some cases), Out of interest, I checked how the symbol reference distribution in open-source projects look like. These numbers are for unique class name references inside namespaces: Global: int(88398) Same namespace: int(83790) Other namespace: int(315455) So, most references are to classes outside the current namespace. The number of references to global classes and classes in the same namespace is actually pretty similar, there are 5% more global references. From that perspective, changing the name resolution rules to always look for the global symbol if unimported would actually slightly reduce the number of necessary "use" statements. > and changing that default would require changing a lot of third party code. > A separate option such as `declare(lookup_classes=global)` would allow migrating to that, > but would confuse developers switching between codebases using different settings of lookup_classes, > and introduce similar confusion about the rare case of multiple classes in one file. If we were to make such a change (hypothetically), the way I would view it is "use new name resolution rules" or not, rather than a collection of fine-grained options. Notably Rust made a major change to how symbols are resolved in the 2018 edition, so such things aren't inconceivable, especially with the right tooling. Nikita --000000000000b8b245059d082e87--