Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108432 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19202 invoked from network); 10 Feb 2020 03:21:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Feb 2020 03:21:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E36EC1804F4 for ; Sun, 9 Feb 2020 17:34:37 -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-mw2nam10olkn2078.outbound.protection.outlook.com [40.92.42.78]) (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, 9 Feb 2020 17:34:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jc53n5VxNuyhlGzEhF35Uu7NBgq1YidSidz2DMsQ3RGDGzFTMzVrRymKlvCU7eKms872hvDCy25JnoypkPG+GSIv8Lp+LD+8/X0lH9HoLAUHN8NDWD0WScyUJlSwRt4yncYkxqdMiKW+t453unP+LXkrNrcqL8eBqPw2Y7CYodCvSe25Oy5En0PIXI5Ve+4nwbImNyw6RY0dmdWfF04cN+yYZxfEcjot+ej0eqqHHmnJMAFBHiVQqLrW9wBwMXei8EJG9NDiO7pqE5VJQo/6Rs/TAWSqiyTIh1HCQ/ZQgfebeEC2UjkLP+sHOGiLTlGOICDv5I3xV2GNzuwUwpjKIg== 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=l0Qjt9UzCrrOL4M+kG5wL0CXBGi9fdS8YwQgzFpUhfU=; b=B/B/X4BCTEimFZTJKtumgIXQcY4PI8+dZGFdc3k7+oGt+Uvb1jmGoMcKCRqMgvcPRtfWziswd/Kg1Kf1Vy6JgWZ2ACkjFjsqTNWfa9GC60Y+hTma+Nbw6YCCv9tXCkXcoqifQB4/mRqUNlUnuzE1loPG8JMGyQ1nHwbE7KA4D2Gksc/wF3rniBPbAcGNHFO1hRKNt897rR0bOaum12mq10z8gPUwHiSymfdVM0cj0WjEZR2IGYAJT3bLlGIJA0qbFjcQp7/K/yQVFlFoTtFQUKyTAeccQV5VkRxUA1r0ZiUMQNfdvr/EFFztPZdanLuONfa+XoO8vsuHy1EprsTq+Q== 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=l0Qjt9UzCrrOL4M+kG5wL0CXBGi9fdS8YwQgzFpUhfU=; b=EDhLAIACKfKpkCrk9EGiqLX9NZlKclILMlFIrN64ii4er55nbaQn0tLR4e5XxaT/dVoTelp1EJMmoCt5Shuj2gXlUd1Y0+CDsOPrFFHbAE5LFgQnFxtmDXwCHhmK8pNB3T26QvHQG/lY7ZI5N7wpCJexe92QCI9z2+8gx/a9XCwk9rwFNAMaIx5j4x4CFse580cioxAREkRGTSVXJO0O5wGZLe9B28+2mmI7vp97Y7TDPeGbetBmgQYLo6y2MiNZiCOv/q4+0nkbm3zJxCb77CeKkHHWmMzxtD42wbaBm7vbw+Sy1La90sqqK+QQoNkmDgcZBptW02/I4ndTWO0P4Q== Received: from DM6NAM10FT036.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::39) by DM6NAM10HT238.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21; Mon, 10 Feb 2020 01:34:35 +0000 Received: from CY4PR07MB3063.namprd07.prod.outlook.com (10.13.152.57) by DM6NAM10FT036.mail.protection.outlook.com (10.13.153.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21 via Frontend Transport; Mon, 10 Feb 2020 01:34:35 +0000 Received: from CY4PR07MB3063.namprd07.prod.outlook.com ([fe80::6064:b0da:81fc:19f4]) by CY4PR07MB3063.namprd07.prod.outlook.com ([fe80::6064:b0da:81fc:19f4%2]) with mapi id 15.20.2707.028; Mon, 10 Feb 2020 01:34:35 +0000 To: Mike Schinkel CC: "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] Allow calls to global functions in constant expressions Thread-Index: AQHV34pQKhYLJVyrNk2d5UBD297T9KgTYiAAgAAGKOU= Date: Mon, 10 Feb 2020 01:34:35 +0000 Message-ID: References: ,<9C0A5E79-6925-43B4-84C6-A2DA007A9F1A@newclarity.net> In-Reply-To: <9C0A5E79-6925-43B4-84C6-A2DA007A9F1A@newclarity.net> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:03EFE089EB6E0DB784D9ACD0D62F9C2BA7707348F551D71F2CCE4F8A3B2F7F24;UpperCasedChecksum:889085ADAC8271F7A9F979AE1ED0666D8A2839AEC752CD0A83380DC4757ACC60;SizeAsReceived:7112;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [PNCSjHxlaisBH4hasMtUNOL7bAjSPJZr] x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: b1e81169-2b39-4da3-3ed9-08d7adc962b1 x-ms-traffictypediagnostic: DM6NAM10HT238: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /BeJzvCUbcBG/lEd355G6tNr9w4yA4UElTx6kEBO2gYYWWrCartezL7rA2gPqqWZcFG9hPqEHnKKjqW7GVu6XaZuizHSwKGEJaZMkbAms6BBMPGyTnRbdpN7VzIVVgZZStoZYFR32zGLk0iorEIhVUDNkmtm1GX6BtFTpKn5id55Cb2tM8Y/84VTB7foxoNr x-ms-exchange-antispam-messagedata: 37NARLRBiHDoDYZUt2p6JJchjh1SQ3V2bjo+oDljNrr+erTteC2vRvg6t6DLu49vLXXKS2wlyGshU25xA3iqleCF+eNlvwAavAsjErxcQ5arMEtZzcGvnExy7XIU/h2MR8E03TMW9jwEZClA2jEpcQ== 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: b1e81169-2b39-4da3-3ed9-08d7adc962b1 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Feb 2020 01:34:35.0590 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT238 Subject: Re: [PHP-DEV] [RFC] Allow calls to global functions in constant expressions From: tysonandre775@hotmail.com (tyson andre) > 1. Why again are MyClass::methodName() not considered for the non-whiteli= st vote? =0A= > =0A= > Seems to me a developer would be more inclined to implement the expressio= ns that define the class constant's value in a method of the class than in = an external function.=0A= =0A= My reasons for doing this were to keep the scope small and easy to implemen= t,=0A= and work on an RFC for methods immediately after if the vote for allowing a= rbitrary functions passed.=0A= =0A= The other concern was the edge case `static::method_name()` in class consta= nts,=0A= but `call_user_func(['static', 'method_name'])` or `array_map('static::meth= od_name', VALS)`=0A= causes the same issues.=0A= =0A= This leads me to a blocker I've discovered with this implementation calling= without a whitelist:=0A= The way PHP resolves the scope is to look for the closest closure or user-d= efined function,=0A= then to extract the class of that function. (in zend_get_executed_scope).= =0A= I thought the scope would work because `const X =3D self::Y` works,=0A= but it turns out ZEND_AST_CLASS_CONST is special cased in AST evaluation.= =0A= My current ideas for fixing this (for class constants and property defaults= ):=0A= (Parameter defaults, static variables, and global constants should already = have reasonable scopes)=0A= =0A= 1. Wrap all of the calls the engine is making in a byte copy of call_user_f= unc, but with the property `zend_class_entry *scope` set, so that zend_get_= executed_scope will see that frame's scope and use it instead of the caller= 's scope.=0A= 2. Add a fake stack frame that acts as if an extra closure (bound to the de= claring class's scope) was being evaluated.=0A= 3. Add a brand new function.=0A= =0A= If I don't do that, then constant/property evaluation uses the scope of the= caller, not the class=0A= =0A= ```=0A= class MyClass {=0A= public static function example() {}=0A= const X =3D call_user_func('self::example');=0A= }=0A= // this throws in the current implementation=0A= // due to no active class scope, and that's a bug=0A= echo MyClass::X; =0A= ```=0A= =0A= If I (or anyone else) can't figure out how to implement the fix, or the fix= has issues,=0A= I might remove the secondary vote from the RFC and just vote on the whiteli= st,=0A= which excluded functions accepting callables.=0A= If anyone comes up with a working implementation for a fix (including excep= tion handling),=0A= I'd like to know.=0A= =0A= =0A= > 2. Do we really want to add a standard library function 53 characters lon= g? =0A= > =0A= > Can we not come up with a more concise name than get_defined_functions_al= lowed_in_constant_expressions(), like maybe get_const_expr_funcs() or get_c= onst_expressions()?=0A= =0A= I was planning to change it if I thought of a better name.=0A= For get_const_expr_funcs(), I'd think it would be important to be consisten= t about=0A= naming in the standard library.=0A= `get_const_expr_functions()` would work, though.=