Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108231 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36236 invoked from network); 24 Jan 2020 20:02:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jan 2020 20:02:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8E5FA18054C for ; Fri, 24 Jan 2020 10:11:32 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.64.0.0/10 X-Spam-Virus: No X-Envelope-From: Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2057.outbound.protection.outlook.com [40.92.42.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 24 Jan 2020 10:11:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rse6SmFgE95Sjs+JqL3ZnXmRezOhFytSkWH2z1bRqbDWdXWJJ9H4Fo28QyUXIPS1pvfI8qnn+/n3MdLvCI65fqzFUBFSSwX5S4tLIvSkD6k/++S388eBK0UNeX8wCGO0y0SiO83BbPGA/18INTDlc/bWqryoXo9NTsvvNHX4W08D7+o46tXJSKBupyGSJY4GJHSr6Yoc/UdcMv976wiOfGDaGeUvMzHF7kNHfXz/9oIbdWCm3JVsrGYIwUn7DNWRMkGOe8I7UMKjrEiyB6Z6Gx/IiCyW6+TLUv+tkQtJXks5Sk5mPDTqo1e0NcRg3NPizrJCe952DfJGhfdF85svGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LwTor/LmOPgFey+AV7GxzwLf1GjpesT3qS5/Xo8BcMY=; b=WK3fYdvBx8zDoqhs0+S7m5+ImyyqIGPOiAbhfojkYxXVFkYfrt+Sf1l+tYwiQh83wZLzyTL5M0BWX9kxob14qnZtiuTUNnlPOe9bgoZjlGv3BVFAfML5Vg80o1n/arCpugcBhT27cCwdrXi7sC2cXbR5uYwDu8AGiBMh3RCtNJBadMYXyqOMfqWbD5TYbgmNVRIVPwjp4IYEBY8xf8oGBOAvw/Qk9PkbSUjGjCLNzY4b2d/lZhBzS/vOigbJxxrMBdl91dQHfHiEa5iu0ctV2fwRMK8Z07D+p6L2JzFSYEyRUKx1X9/J/U4LC4S2J3AUOkxujpMNQAY0DP25wfV9MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LwTor/LmOPgFey+AV7GxzwLf1GjpesT3qS5/Xo8BcMY=; b=QQTQeDMXlprnirCEgSMi7YPR7hOyyCYlI+hHpqvZErifDwx+h0rc6GMsqbNUSEVedjRsBQTrNNca8I2w8Z5MzYcQKIsK6Ja2snqixGiincGUQunIsZxzwHpi0Q7H+rOFVtrWjK0a9E6qHHAMv67UePvMErOSx/IB8UGjWBtnMxnqDMrs/CU4zxx+DWYXNmunwv1pyoo4PSeAPFF2WrQuG061urfxkEuF98SS9DzLllMuOZkFz4h2bApjY8g1MDaxq1oimMTlg4wshIbOska8vUktrv/AzELBwaMFImh9lEEVFTTtRkHS70u+VIDmsdk3jJ0/+2xK8uj6f2wHBz+PVQ== Received: from DM6NAM10FT007.eop-nam10.prod.protection.outlook.com (10.13.152.56) by DM6NAM10HT168.eop-nam10.prod.protection.outlook.com (10.13.153.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.19; Fri, 24 Jan 2020 18:11:29 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.152.58) by DM6NAM10FT007.mail.protection.outlook.com (10.13.153.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Fri, 24 Jan 2020 18:11:29 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb]) by DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb%3]) with mapi id 15.20.2644.028; Fri, 24 Jan 2020 18:11:29 +0000 To: Nikita Popov CC: Mark Randall , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: [RFC] "use global functions/consts" statement Thread-Index: AQHVwNgGtev425C1jEaW2/fYCDQJoKfqjUCogAA6vwCAABZSCIAF7qHQgAA+1YCAABKbIoAI/p4AgAAhc/4= Date: Fri, 24 Jan 2020 18:11:29 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:598AACB982E023955FA45EBCC35615E6040878DAFCEB564617CC52B03AC155DA;UpperCasedChecksum:6EBBAD191F163EAF3D06DE1DB0B0BA9167A94F5078D5EE4682C8C7F1271DF269;SizeAsReceived:7691;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ZQdIxtmdk4YousmCLieCf1zT5tk8l+Vb] x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: c8fe9a4b-180a-4799-e5be-08d7a0f8d5f6 x-ms-traffictypediagnostic: DM6NAM10HT168: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nETu6j3HeMW/GY8OdEqu/Uc3Imjj/HjbOp6co9gf8y4zQrHjGS8BI7d6afc8+/GFnL2ScMa06rgc/KM1Q1ploM4ltmi4aANeRiQid24bIVXYvDhfrPgaJEmLZMR+xP2VlIZUurydP5bQsL4kOZ59xiTlei72q9WNzVnAh8G3N0+QqyTtfMDiiQawtp2m7PwONjM+FuIPEnEGDxltXGI/fEwz06DaINt6+CPRe7Twsxw= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: c8fe9a4b-180a-4799-e5be-08d7a0f8d5f6 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2020 18:11:29.7206 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT168 Subject: Re: [PHP-DEV] Re: [RFC] "use global functions/consts" statement From: tysonandre775@hotmail.com (tyson andre) > I like the idea of using a meaningful value here, but think that this=0A= > should be using a string, i.e. declare(function_and_const_lookup=3D'globa= l')=0A= > rather than declare(function_and_const_lookup=3Dglobal). =0A= =0A= Also, I could make that a voting option, and it could be changed before 8.0= alphas if new concerns come up after a vote.=0A= =0A= > This looks a bit peculiar... We could also say that declaring a symbol al= so automatically brings it into scope.=0A= > I'm not really sure which is better.=0A= =0A= Neither am I. There were edge cases with doing that that may cause more con= fusion=0A= =0A= namespace NS;=0A= function f() { /* calls g() - which g() */ }=0A= function g() { /* calls f() */ }=0A= =0A= if (!function_exists('NS\h')) {=0A= function h() {}=0A= } else {=0A= // what will h() refer to=0A= } =0A= // what will h() refer to=0A= =0A= > As a general note on the overall proposal: I think this is a very pragmat= ic proposal. It addresses a real issue, and it addresses it in the most str= aightforward way. You can just drop the declare in your code, and it will k= eep working exactly as it did=0A= > before, just faster. Assuming you weren't doing anything stupid, of cours= e.=0A= >=0A= > The big downside is that this makes class and function symbol resolution = complete opposites. Classes only look in the current namespace. Functions o= nly look in the global namespace. This reflects the way they are most commo= nly used, but is not a great=0A= place to end up from a language design perspective.=0A= >=0A= There are two alternatives that keep class and function symbol resolution t= he same: One is to always only look in the namespace. This has been suggest= ed a few times in the past, including in this thread, and the RFC=0A= https://wiki.php.net/rfc/fallback-to-root-scope-deprecation. I think this i= s a fairly unpopular option, because using fully qualified names for functi= ons tends to be quite ugly (more=0A= 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 doz= en different string/array functions.=0A= =0A= Agreed=0A= =0A= > 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.=0A= > This would match the proposed semantics for functions/consts and change= =0A= the resolution rules for classes.=0A= > 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.=0A= =0A= Also, about the note on classes.=0A= =0A= It's fairly common for NS\SubNS\ClassName to mention other classes from NS\= SubNS\OtherClassName right now,=0A= (more commonly than use Exception, use Throwable, etc in some cases),=0A= and changing that default would require changing a lot of third party code.= =0A= A separate option such as `declare(lookup_classes=3Dglobal)` would allow mi= grating to that,=0A= but would confuse developers switching between codebases using different se= ttings of lookup_classes,=0A= and introduce similar confusion about the rare case of multiple classes in = one file.=