Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108251 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21498 invoked from network); 26 Jan 2020 18:15:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jan 2020 18:15:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 327B91804D1 for ; Sun, 26 Jan 2020 08:25:33 -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 ; Sun, 26 Jan 2020 08:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kXzSLzDpaZ4dmZdjjD0Ja6HdAXPeZTTHk0mH2tn3sI7m7hJsh6g0my3qwk0RxyiX3+OUyRfg2n8lL853f6SHojtLMBmjQrRsQaXuJM5VN1qaZWnyhfQFTebEIo001F7uBCUmC1h/9rUUW9jsPpF5UVSw0fORTK7GPq83d8CAtEyGIddB7ugoF9PC0JYPnQTYHI+N0bVvMpiC/6GKHYgtI53FkqJSdW15PhsbvAhaycJb0oKxK03/2YlCEbx6gx8zr0uFoiFvFwWIU+gv/hmk+Lvny16s4MSUBAXUqN8Ttv/xDFbW6H/0ob2eDz0BES1VLbU5SI9/w0hUIkJwLNMpwA== 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=tnkVPGznxm5gdWGp9KDpIb6w+g6CxBzSLUmsUYEkAMU=; b=hTlQnc1M1Pm8biu6wsU8ru31/Mdg1QuMUy54jlXdG2mYPynRZPBanT6Ig0VpeL3FWybzhOd6PND5aW4khBgdFm++UDOu0/3mVm5DxX49VMmF6BBljEQlq6ToWtI1XO8jFiTqqQ39CgrOszd7QdV9YdAHPGa7DHy9AirblKa91RMUugG1T4+B73lrX6YItu4pxUo8IcSk2qxmiNXeYLlGknHQTyoWU8woHDccof1Napj4tnYVpjzZEIM9M+tS1T/TQbKjJAwSgCbiPwGBCKIFNhC7wFma0WCd6zPweyTzh/S0MpvbdNtTNTD7KQhoykI+H3g+tFTBhD+J5ttqLKNRHw== 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=tnkVPGznxm5gdWGp9KDpIb6w+g6CxBzSLUmsUYEkAMU=; b=gxEwPl0wfLJ//32Y1u6M4aH7QJZVExfAtAaiSE+vWq1KxrWRvfqe27XwYlE9Qg+EQhfQ0L+5xTOlUCzYjUvNydy+BhGdlngQNRDZXGyBo+vzVUmflgPopp6ewtJjGpefy1NC0Qw+OjWsJLcoPhW3iuQ0nyQ/d2+H+qu4qJk6Pbd8JJMIBZ5JS6EZ+0X6E75qbSPK/tBuLAMCyXibhIna8LqeJ0vSB9N2gCfiHOxbq8ExN2sCSQD3SIbC/qkl2KBMDjv5dnithkco8dZwc+gk1pajPObQ2gG2RcRs2EXQTgT2S9JLo+Z04e8TbZRsHfrE2uoaImySYZq2H+KhSeOODQ== Received: from DM6NAM10FT022.eop-nam10.prod.protection.outlook.com (10.13.152.59) by DM6NAM10HT244.eop-nam10.prod.protection.outlook.com (10.13.153.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18; Sun, 26 Jan 2020 16:25:29 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.152.53) by DM6NAM10FT022.mail.protection.outlook.com (10.13.152.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Sun, 26 Jan 2020 16:25: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.2665.017; Sun, 26 Jan 2020 16:25:29 +0000 To: Nikita Popov CC: Nicolas Grekas , Mark Randall , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: [RFC] "use global functions/consts" statement Thread-Index: AQHVwNgGtev425C1jEaW2/fYCDQJoKfqjUCogAA6vwCAABZSCIAF7qHQgAA+1YCAABKbIoAI/p4AgAAC2gCAABgFtYACp60AgABaA0Y= Date: Sun, 26 Jan 2020 16:25: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:DA846B74F8375F12913A897B849B091C03987311C93C6A30E6E859110146EA4A;UpperCasedChecksum:E7E5E900A45C867D0F4083A4ACA29CE9BB09E21F18BE86C7743FFB9EDDF00C21;SizeAsReceived:7962;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ntCi/0lfTXrjdBiA5PXRHk+Z/FSIhNKu] x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: e041e8d7-9d90-49cb-4975-08d7a27c5bfb x-ms-traffictypediagnostic: DM6NAM10HT244: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4tx5m8ZkMK+1CSuPsmMIXJQuGbbrE7WT8OX+rT8zYNS/y/r7vZWin42hPsEtpAzI+qWlqBeYfsLIen9C93QK78qVbeJWgmXKvoIpJTBcQY3eL+tgUHIPE1v57wxFBsfjdaSd1DRs7fdPa+cyfQPUIlw5iifLKx4Hk1DmXIU3/7ZAxSNhcb+yE9eEr5hoMw6p0TsvoAHEw5sGAQTcrgrvQN8veffSnoxZL8kHWBCrAfg= x-ms-exchange-antispam-messagedata: Azh1nCcqH2wWLs8wWSq9nPXA6bn0bvhw0poqkcf8VnnmCp7Z+zePQdk5mNvTFsdkdf6M2lzKEVRnIZ/GlOJvRQj76j0/DrkC+w5D1h41tzrfiP5dpCIy+r/dFu5togN/hVXaEJeM7Z0nNXp3Gdb+7A== 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: e041e8d7-9d90-49cb-4975-08d7a27c5bfb X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jan 2020 16:25:29.8034 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT244 Subject: Re: [PHP-DEV] Re: [RFC] "use global functions/consts" statement From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= https://wiki.php.net/rfc/use_global_elements and the implementation has bee= n updated again - the syntax is now declare(function_and_const_lookup=3D'gl= obal')=0A= with a literal string instead of a keyword.=0A= The voting option for whether it was a string or a keyword was removed.=0A= =0A= I plan to move this to the voting phase on Monday, if nothing else needs to= be addressed=0A= =0A= > Saving two characters per file doesn't seem like a great motivation to ad= d additional special cases to core language syntax.=0A= > Right now, declare just types "identifier =3D expr", while with this chan= ge it's going to be "identifier =3D (expr | a | few | extra | keywords)".= =0A= =0A= Thinking about it again, I'd agree with the parsing special cases being inc= onvenient.=0A= =0A= > So, most references are to classes outside the current namespace. The num= ber of references to global classes and classes in the same namespace is ac= tually pretty similar, there are 5% more global references.=0A= > From that perspective, changing the name resolution rules to always look = for the global symbol if unimported would actually slightly reduce the numb= er of necessary "use" statements.=0A= =0A= It would be more understandable for new php developers familiar with other = languages if name lookup was consistent across classes.=0A= =0A= I don't have as strong a use case for this as I do for eliminating the func= tion/const ambiguity. Changing class resolution (via automated tool) would = require more code changes than function/constant resolution, and the classe= s are already unambiguous.=0A= =0A= > If we were to make such a change (hypothetically), the way I would view i= t is "use new name resolution rules" or not, rather than a collection of fi= ne-grained options.=0A= > Notably Rust made a major change to how symbols are=0A= > resolved in the 2018 edition, so=0A= > such things aren't inconceivable, especially with the right tooling.=0A= =0A= If a setting affecting all name resolution was added, then forbidding the u= se of both that new setting (e.g. ) and declare(funct= ion_and_const_lookup) in the same file would keep code simpler.=0A= =0A= If "use new name resolution rules" was the only option, the larger amount o= f refactoring for class references (and doc comments) might discourage usin= g the new name resolution for functions/constants, and make backporting pat= ches to previous major versions of applications/libraries more error prone = (e.g. \MyNS\Exception vs \Exception). The refactoring might also be perceiv= ed as risky.=0A= So I'd still want to see the voting results&feedback for function_and_const= _lookup before investigating approaches to changing class resolution.=0A= =0A= Rust would also catch many more possible bugs in symbol resolution at compi= le time.=0A= The static analyzers for PHP can detect almost as many bugs, but would requ= ire that people be aware of the analyzers, configure them, and use them in = CI.=0A= =0A= - Code such as if (class_exists(SomeClass::class)) { /* Use SomeClass */ } = might be permitted if analyzing class_exists conditionals is a feature of a= static analyzer.=0A= =0A= - Tyson=