Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108430 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86572 invoked from network); 9 Feb 2020 22:49:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Feb 2020 22:49:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1E9F180210 for ; Sun, 9 Feb 2020 13:02:41 -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,RCVD_IN_MSPIKE_H2,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 NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2088.outbound.protection.outlook.com [40.92.23.88]) (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 13:02:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z6xYPuK2JrU3oJC3dprwISqHxfO3sdKXp5yV8J3hmnvu4kBCQOClTeEbAzgJZI9vdRp8ZaYcityYJDwfeYnkPv295FrA2ZOC2uPi+8hWgQ4xqmt9Pw6JOaKTsdK+m4xhycIFaC5KYJca89SxKY8rZnZjGjev4cUJKnN0qElfFnAYXYHY7iBdmpcJRy62GmwSGKcBgalmW/JfvMurCUZHeoWZSmlEtU1EcJ7mEoq9Dq6kU0pKNgU0roKnlbercLzKWebkawh9rrFHioFavSKGUnFzTzk717G3YTI6SJNV6lLP9Wiux2D8HWfAJMlKQtyrSCfdMDThWcA3gqAvpcfUsQ== 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=AGv60NricLKhkuf1nlWWgne4i2o7N04oMH/axVbwqZs=; b=halarWtu5R92+TWBQHoV3EtzFDenzGmq+SpWWxn/LRhyjY6u1WS2PDYSyK1DqtIfPWycsXDxt1qWl5LPFMJvSK+E3PVF3D3SSTFoDNH+n2ZrWHMPIOAAhl/iwLuo7RBk2laC9lAqxeBcpL9MUZ2tjARvPl2bxp4YmcUFxFY6LZHQufUEH1f0UROSWyzp9QgNUIf/Wiy8jlMBu6ZnKT8fLDCYimrbr9FGsQbRiIMsCTj9XkmXIwTN2AYkiH4f3C0kg/EDYudQtbB/m66NXNFbl/hMVAxZ+jldDZS+rEwdXqE86mCai6/HD0A2aoqwwfefw31cDMjjI5ChETYymg5yAg== 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=AGv60NricLKhkuf1nlWWgne4i2o7N04oMH/axVbwqZs=; b=vBxKqkOmxaIAGZ0B5XM5dbaFiRwfto2SUbUrBk6l76BV5iiGPhArKhZE1zLyNoVlO6nuK6P3CYaiWMtVSpUroUQcKVtey3Z+unItiADBmjuqnt8GugEFJk3ecE/sh9AB3eITYvCA3F1tfdfXiXBMuznJTpCs3OJia03Rz5E5lVncOIMUB5IGbkme4grMHrc0UWoSMGFS/MY7Dq1fgJI8U3L3QBX6jpFOusPUNYoGPiy2nqfAI5w3OeEg37KiQcTbIld1nWftbBEvOKevHfI7goI1fwEhl/HURbTjTL5JLHD/IQFag3w5ZtxvwD9GEDWCJHgASzUp+0LWDw3hOkei2g== Received: from DM6NAM12FT026.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::37) by DM6NAM12HT142.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::464) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.10; Sun, 9 Feb 2020 21:02:39 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.178.58) by DM6NAM12FT026.mail.protection.outlook.com (10.13.179.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.10 via Frontend Transport; Sun, 9 Feb 2020 21:02:39 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::1133:bcac:caf1:d588]) by DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::1133:bcac:caf1:d588%3]) with mapi id 15.20.2707.028; Sun, 9 Feb 2020 21:02:39 +0000 To: "internals@lists.php.net" Thread-Topic: [RFC] Allow calls to global functions in constant expressions Thread-Index: AQHV34pQKhYLJVyrNk2d5UBD297T9A== Date: Sun, 9 Feb 2020 21:02:39 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:89BAED132F096998D2C0C35C1345B9E95C08D18F9331E82F5CD427064DBC723F;UpperCasedChecksum:4DDF79667E6867EBB22A8ED0A4FF4A54620B6902C6099DB178DD2B8F7CD2214E;SizeAsReceived:6743;Count:42 x-tmn: [eRQGlvWVYTf9L98j12qNSktB/NZjsqMw] x-ms-publictraffictype: Email x-incomingheadercount: 42 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: bdbe32a9-c1c1-4208-be6b-08d7ada365a9 x-ms-traffictypediagnostic: DM6NAM12HT142: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +vmKxRutZUW+24EDHrZjCsxMkajHr8mqU1QQTbhU4BqROKKvDSQJP1QiH5YMX7tsto9IqYfLr02uS87bOWg8c5NHnINFWcbZlaZrPqcWgnlA2TpjJ0v7Sc28nu5+eshNBKbqJH2Yh3DlDv+ILLkC6tu/zMhv6Bw31ivqxYICOigIw5nxOL1CTzYafRAAiNKfH115qSw3feTMzNAO9Q7dEAHCgNz63FDnC5R81CpMIlU= x-ms-exchange-antispam-messagedata: h9WLGU+mgJNg7tzI+jWdSB6wCeivIT5ijmH27EBsYDstRahVIAYcg7PUEfnm18tsiXNn2ZQPq/DNH8k0UgzrXh4hZBpJvsDPwxvjOe6KghxXg9/RO0mbFUKWhwGKYtXvoTVDIMc8HTtss4zesHUZ2g== 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: bdbe32a9-c1c1-4208-be6b-08d7ada365a9 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2020 21:02:39.2172 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM12HT142 Subject: [RFC] Allow calls to global functions in constant expressions From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= https://wiki.php.net/rfc/calls_in_constant_expressions has been updated and= moved to=0A= "Under Discussion".=0A= =0A= This proposes allowing function calls in constant declarations, static prop= erty defaults,=0A= static variables, and parameter defaults.=0A= It includes a secondary voting option to allow any function calls,=0A= and not just a small set of whitelisted core functions.=0A= Other expression types would continue to be forbidden in constant expressio= ns (variables, method calls, etc)=0A= =0A= Let me know if you have any comments on the RFC or implementation.=0A= =0A= Earlier discussion can be found in https://externals.io/message/108343=0A= ("Planning an RFC to allow calls to global functions in constant expression= s")=0A= =0A= I made some updates to the RFC, implementation and the proposed whitelist o= f functions.=0A= (in response to https://externals.io/message/108343#108427)=0A= =0A= > > As you've already realized, the main problem here is the behavior for= =0A= > > functions that have side-effects or state. Currently we mostly get away= =0A= > > with the illusion that it doesn't matter when exactly constexpr=0A= > > initializers are evaluated. Apart from the error location and (admitted= ly=0A= > > quite a few) other details, you ostensibly can't distinguish whether th= e=0A= > > expression is going to evaluated on declaration, on first access or on = each=0A= > > access.=0A= >=0A= > Good point - If PHP ends up supporting an option where **any** global fun= ction can get called,=0A= > It'd make sense to evaluate any expression *with a function call*=0A= > every time for instance properties and parameter defaults=0A= > (e.g. `public $id =3D generate_unique_int_id()`).=0A= > (the optimizer can later optimize any functions where it won't be noticea= ble).=0A= >=0A= > I think that would require updates to my PR for caching,=0A= > since immutable returned zvals (including false/true) get cached permanen= tly.=0A= =0A= I've completed the updates to parameter defaults.=0A= Parameter defaults containing calls now don't get cached:=0A= They always get evaluated every time the parameter isn't passed in.=0A= =0A= I also excluded support for calls in instance property defaults from the RF= C.=0A= I'd want that feature, but the changes to PHP's internal representation of = classes expand=0A= the scope of this RFC too much for me.=0A= =0A= - PHP currently evaluates all the property defaults and permanently caches = them=0A= the first time a property gets accessed or an object gets instantiated.= =0A= I'd probably have to change the internal class representation as well to = fix that,=0A= and I don't know how many or what types of bugs/issues that would cause.= =0A= =0A= > That reminds me:=0A= > I forgot about functions such as `compact()`, `extract()` and `get_define= d_vars()`.=0A= > (and `func_num_args()`/`func_get_args()`/`func_get_arg()`).=0A= > It looks like all of them check `zend_forbid_dynamic_call()` to throw,=0A= > but I need to add tests and possibly flag the call as dynamic.=0A= =0A= Update: The implementation already properly throws an Error.=0A= =0A= Thanks,=0A= - Tyson=