Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108580 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58089 invoked from network); 14 Feb 2020 17:03:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2020 17:03:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4EB91804F2 for ; Fri, 14 Feb 2020 07:18:19 -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-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10olkn2056.outbound.protection.outlook.com [40.92.41.56]) (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, 14 Feb 2020 07:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JlbTmQG38qaclZ1MUK8/kShYaL6tEAMfFy4aUEfSa+DIH9ElJJ86hFlydDxd4tEhgTHPUgbDhB9r2nKZqwCD3MkC7SQNWLD26WBIrwtPo11/uu3mgIbPUSvMwxrneiq+KOBnrI5Ojs0BbIHq6rrHolhwDxq0AYc/qTXRi/iToR2fUSigTqFptT9HbU531Ip3n8lPepkucMhsK6jGhP65W3y5JcvCcX6jMhry4fq1b1Wg+Xvheu405yR6aKa8iAOcztFf1oIvPazPos/WWeqrHeP8oz/yyPw4V4pxEnyEz37exzIdDn/oowWu81bf8JAyr/ExmZuPJKc2wjKVzInkNg== 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=zka1baFantoZJ0Xw69o9GbxKXzhMB5fR9niwGKL7uoo=; b=P3304hGuTDv/S3umMp391b8onGKLQuhA7ZUDUpn+RKNRX7CyKYGYhLmcXiJM+Gld6DpTLQ2wpyFzmI0REFJQKPYigFGpj8keIa060tESGQ6bgC/eLNbPMRmN4Bgs9wIj1wcCjcsUpwRE4BqWP6BvV5Ek/VY9PWpG/JepZjNMBYxkdrYNLhXi2n2T6nOgi1RMh9BoHC8XIDSraxrHtPihRUMbbDGemfnxWl07xJ6ut0DN0KlJEkGcN2Pd5pBtXvoGmOic33IHAQXTfzrD7o1hx22pxKO+59CKA2sfaQmZnliyC96xgcRCZfYf97ZO94V/Du52EQERj4XKSYk0zONr6Q== 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=zka1baFantoZJ0Xw69o9GbxKXzhMB5fR9niwGKL7uoo=; b=H/x3BdFb1Y/wAKqvX0SCVkcIhjow1QukUtD+ncYXmJ8lw6SZuctPyWqcfUxf7gSdnEXZQRXLVDA5Am9zZawBVA5+UMFAjQog5l8HGDarLNp/kkGEKz37qxQLfQULzQidlta1htkFJEkpFAmc1ri/LGWGrbsZGsSwmBWyx4hW+yd7Fq/FE6XVM0bCVFLyPHUiwbSqjevDIQShJR2iSZ8a1rWvXTvAx2315TskAIa6/+x8XsUGRDA3d1lJLNAHyb7tLwpZoF6/IVUTxbC6sYRexOVcTlheNndkPAtOlRFk6wNVyA+fqla9MptKE0P26nOhK0ddsO+6iy3XmJWammT3XA== Received: from DM6NAM10FT010.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::33) by DM6NAM10HT138.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::284) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22; Fri, 14 Feb 2020 15:18:17 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.152.55) by DM6NAM10FT010.mail.protection.outlook.com (10.13.153.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Fri, 14 Feb 2020 15:18:17 +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.2729.025; Fri, 14 Feb 2020 15:18:17 +0000 To: "internals@lists.php.net" Thread-Topic: [RFC] Allow calls to global functions in constant expressions Thread-Index: AQHV34pQKhYLJVyrNk2d5UBD297T9KgazPi/ Date: Fri, 14 Feb 2020 15:18:17 +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:09CCF36441D3B1699AED4850B3CDA409174452ED15006D70B811ADCC575790B4;UpperCasedChecksum:C4BD0772D63BAF2B0AE6551012452B2827C91EDA79BBAF9BA21E3F57C4509465;SizeAsReceived:7000;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ikSqeqUTvGE+ZHrd6Ufl8tJ9BE0HPlPr] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 13c3afdb-83ac-4c1a-2f3a-08d7b1611e8c x-ms-traffictypediagnostic: DM6NAM10HT138: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lR+pugTTUaaMigyOLDVYjs1JmC5dBavW6bKoWhuOj+trLHOaKyiI3Ngq36JZpXORQCW1R490mN8BWR6KVKcYb/Dyx2+8xl4Par17sRVTx1nVxOuvWXHYhQnbodvc4wRgfcdQqfWjSvDZ4tjXbEIs/uBhlpSNVyInDLtijFInJZcyMOAVogKNkmD0W+nEGoheM3HtqWW1zX/6gifJO0wszL3ewBR3lscYrlYS8hBbo3Y= x-ms-exchange-antispam-messagedata: 90gTT9S2adLIJ2ZWfeqeTx5d2gTP8a2bN56U7BPnFQNQyHNtMXN4ZyNgQVjZ8qvavvRl9HzafZEv9PbZ6zrZTsfLg/Oir+sJgwDPpmiYofaCR5/NPfTWWyp9NGRjtM/paJpVM4qv5w4GVWgZ2tCaqA== 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: 13c3afdb-83ac-4c1a-2f3a-08d7b1611e8c X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Feb 2020 15:18:17.3294 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT138 Subject: Re: [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=A0has hit some roadb= locks in the implementation shortly after the last email.=0A= I've been blocked on how to resolve them in the implementation in a way I'm= certain would work.=0A= I had assumed the calling scope wouldn't have the below issues when I start= ed working on this RFC, but was mistaken.=0A= =0A= =A0- The helper method the C code uses, `zend_call_function()`, will always= act as though `strict_types=3D0`. I'd consider this a blocker for `declare= (strict_types=3D1); const X =3D intdiv("123", 2);`. (Internally, zend_call_= function adds a fake call frame without a function, similar to what=A0__get= , invocations of error handlers, etc do, and that call frame makes the para= meter parsing helper macros of the invoked function treat it like strict_ty= pes=3D0)=0A= =0A= It may also be desirable to specify calls in constants always work like= strict_types=3D1, to avoid issues such as `strpos($float, '.')` being loca= le-dependent)=0A= - Getting the class scope *of the constant declaration* to work properly w= ith `callable` (e.g. `public $x =3D array_map('self::helperMethod', VALUES)= ;`).=0A= This isn't an issue with only a whitelist.=0A= - Solving the above two issues while continuing to throw for func_get_args= (), get_defined_vars(), etc.=0A= get_defined_vars() would throw for dynamic calls, but the above approach= es would act like =0A= =0A= Currently, my best ideas to fix some of the 3 issues were:=0A= - Create a fake zend_function placeholder in C with a placeholder name and= add it to the internal stack of calls (EG(current_execute_data)).=0A= Currently, though, it's only possible to set strict_types=3D1 for user-d= efined functions.=0A= - Create an actual closure when compiling the code, which would be evaluat= ed the same way as `public $x =3D (static function() { return array_map('se= lf::helperMethod', VALUES); })()`=0A= (i.e. a closure without any `use` variables. The )=0A= =0A= This would solve it, but the performance would be unexpectedly worse th= an expected, and that would interfere with optimizations.=0A= - Create an alternative to zend_call_function, but that would duplicate co= de and be error prone.=0A= I'm not familiar enough with XDebug, NewRelic, uopz, and other replaceme= nts of zend_vm_execute to know if those would be able to support that,=0A= or if there would be even more issues I haven't thought up yet that woul= d prevent .=0A= =0A= Second, I realize it doesn't make much sense to restrain the constant expre= ssions for parameter defaults and class constants in the same way.=0A= The RFC was coherent proposing allowing any function call in 5 places, but = less coherent proposing a whitelist of functions, even where those restrict= ions weren't necessary.=0A= =0A= - It may be desirable to support many extra expression types in parameter d= efaults and static property defaults=0A= (`function myFunc(object $x =3D new DefaultObject()) {}`)=0A= but still limit class constants to the proposed whitelist of functions.= =0A= =0A= Third, I was considering a straw poll for this,=0A= but don't know what's required to set one up.=0A= It also didn't make sense to me without a solution to the roadblocks.=0A= =0A= 1. Desired expressions in param defaults (No change/Whitelisted functions/A= ny function/Any method + new X()+others)=0A= 2. ... in static property defaults=0A= 3. ... in static variable defaults=0A= 4. ... in class constant values=0A= 5. ... in const X =3D ...=0A= =0A= Thanks,=0A= - Tyson=