Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108345 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97465 invoked from network); 2 Feb 2020 02:15:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Feb 2020 02:15:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BF18C1804DA for ; Sat, 1 Feb 2020 16:27:10 -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 NAM02-SN1-obe.outbound.protection.outlook.com (mail-oln040092005016.outbound.protection.outlook.com [40.92.5.16]) (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 ; Sat, 1 Feb 2020 16:27:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nVvzEvZM1z064kGPOJV2IyoAGNYjL47Il2kVL5koX8DQEQbfKiwMLb+cPQIEeqfzoPrE9xtUntAQ01KypckNBtaQa3o8LkbZzgrAy2rR5aAXj0BcykfzP0XGv9DRhZFpaGJo781axhqEOkiHPvpRD3u7okJWqKXocOoq72302eTmuwjZWYL/O8QGTOzdNCSCr6mZ02JEQjfqweFTbnNbEYaXRgLFwuQCvFcCqAweDkESTigmz8L6l6Bsjlzaj8neQ0ECJxgkEwcOsEsiDOu+pHtFW0xWZEH8BDRHZJyepZcNliecmQE8UrK+DN94us0k1/fFolTOLjVRzjPox7HuVQ== 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=TFnnOt63+dj1bLhAZIZ8iB8J8965hm00WjlCDsrPpds=; b=hc/eppX9Kk3Bebq+mbwWem01We4dfgkJ9vdupcWXeJ4UIS6XrQ2P5vVNUc9LVJAz/H8bLkh8nGfLvTH8bzlbzyZy2ZYjzL//uEk7N4zyNO8TVqHaPtelMY3PRsIQHEduRnDoMcbunKb13+mm6IRq7++vOr83HN4Rq7IJ7GqadQ6VfZalVa2xMKg3K62PpsH0l1ia8YJ+v1mSkZt67PXokKS1+ZIU4PYNeyfv1APD3qpJhcUJUjasiCHjfcevMu1qbFV7QJVXF/THcN7UJ3lKTNKiV3T3RGeq4Ny9ydSwT36hqKTcVmZ4Gob16guTCgEaJUg4ILQwodCVYrRj1KFruQ== 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=TFnnOt63+dj1bLhAZIZ8iB8J8965hm00WjlCDsrPpds=; b=SFR8SKg3WgXw0Q0w0IPW5onYvM1uzcpRMF5hGWktDVz6j4wjrE5qG4jfGDAMbWVZ9ogRwc1MqkEDKxssMdKBp8DVj5fCMTfrK0C+HzNX+JWwmR1S4e578JgvsiBw4/wFBRq4PzENn/hCFgYEgRS4MXS772Pmj9CECthrDudzMfSs5sa9V8yRwdY+3XDDEDhcwGSU7fOzekJSVF6Pv3uIbD3s0qmF3A2n9mg92s75/yQT2xlXXqhqzUz66nYJ2N6vOeJ+oU0scifyXc2ldXtKmL0jv5w6soNmSeKQGu+9muDZrJCUCsr/5+oUl2AbtNrSxpCVEJATrpb3ksZMz8TRFQ== Received: from SN1NAM02FT051.eop-nam02.prod.protection.outlook.com (10.152.72.51) by SN1NAM02HT106.eop-nam02.prod.protection.outlook.com (10.152.72.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.25; Sun, 2 Feb 2020 00:27:07 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.152.72.52) by SN1NAM02FT051.mail.protection.outlook.com (10.152.73.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.25 via Frontend Transport; Sun, 2 Feb 2020 00:27:07 +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.2686.031; Sun, 2 Feb 2020 00:27:07 +0000 To: Stanislav Malyshev , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Planning an RFC to allow calls to global functions in constant expressions Thread-Index: AQHV2VGmZkZM3HvoRkWNVub65jMyhKgHAjiAgAAFIWs= Date: Sun, 2 Feb 2020 00:27:06 +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:6343B4A6933F24AE72EB21A2D781D3647BF6A0D2402C9E05D7F7F3330EEFF7CC;UpperCasedChecksum:FCB6C72FA0ABD478F979DBEE467C6BCB205C7A233588F73FA5ABCB262CA8C855;SizeAsReceived:7126;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Hx8yjYs6NNpvn+5Ny+p5i9SoJ8BveACD] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: da398598-5d1e-4787-8fdb-08d7a776a291 x-ms-traffictypediagnostic: SN1NAM02HT106: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: el1sBd+5ORQd8CRUo0YjhZSMExuR0A8LDRYDD96xOKMcaGobBhtTbh2/CtAXKD7Ep/SeCf1ozXPQxvJXU3zYGbMOoHaLHcVd3bM0Fb7rU/tNK940dCwsEiJ8PVOTYYTHJJaX2vyol8/0L63AAaQhJm6jKa495lc5r5CpGjxzjfzX/4QUXrDv+PfOR4KB/FZL x-ms-exchange-antispam-messagedata: K7GP/YYtkhK7zoHsB0PMpjNduO/AHBXmnqngkR9AnuoGEoydnZ/Yi6wERRGwJKYid76HG2iSu/EZQXO10MwAIlN/esCqNetlEtG1IAtP+7JIE9YFdpOVCgrjs1mMHHn7iLznseHmEyQlXaps4iS4qg== 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: da398598-5d1e-4787-8fdb-08d7a776a291 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2020 00:27:06.9163 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT106 Subject: Re: [PHP-DEV] Planning an RFC to allow calls to global functions in constant expressions From: tysonandre775@hotmail.com (tyson andre) >=A0What happens if a function like strlen() is applied to a non-string=0A= > argument? Conversion to string is certainly runtime-dependent even for=0A= > primitive types like floats.=0A= =0A= Good point. I thought that string casts were already allowed, but was mista= ken.=0A= It's possible to cast to string through concatenation right now, so it is a= somewhat pre-existing issue.=0A= =0A= ```=0A= php > const X =3D (string)2.3;=0A= Fatal error: Constant expression contains invalid operations in php shell c= ode on line 1=0A= php > const Y =3D '' . 2.3;=0A= php > var_export(Y);=0A= '2.3'=0A= ```=0A= =0A= Possible solutions:=0A= 1. Exclude functions with string parameters, strval(), strpos(), etc. from = the limited set of functions in this RFC.=0A= =0A= Subsequent RFCs can be created to vote on for adding those groups of fun= ctions.=0A= 2. Always treat parameters in calls in constants like strict_types=3D1 - It= 's doable and won't break existing code, but I don't want to add that incon= sistency=0A= 3. Keep existing behavior in PR=0A= =0A= Currently, the implementation is intended to respect the strict_types setti= ng of the file containing the constant expression, so strpos, strlen, etc w= ould have that issue.=0A= I still need to add a test that the implementation is actually doing that.= =0A= =0A= > Not sure I understand here - when these calls will be happening? And if= =0A= > you need a value that depends on runtime calculation, what's wrong with= =0A= > using define()?=0A= =0A= The constant expressions will be evaluated at the same time php currently e= valuates constant=0A= expressions.=0A= For class constants and static variable defaults, they're evaluated once at= the time of use=0A= For global constants, they're evaluated immediately.=0A= =0A= If you want to use the define()d constant for a class constant, that is pos= sible right now,=0A= but it's an additional constant that's only (ideally) used in one place,=0A= and there's the possibility of choosing conflicting names if the code is co= pied.=0A= =0A= Another problem with using define() is that opcache cannot optimize global = constants,=0A= because define() will emit a notice instead of raising an Error if the cons= tant already exists.=0A= So the performance is slightly worse.=0A= =0A= And the code is slightly less clear because of the indirection.=