Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:108723
Return-Path: <tysonandre775@hotmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 64790 invoked from network); 23 Feb 2020 03:45:04 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 23 Feb 2020 03:45:04 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 8E6AE1801FD
	for <internals@lists.php.net>; Sat, 22 Feb 2020 18:01:51 -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: <tysonandre775@hotmail.com>
Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2100.outbound.protection.outlook.com [40.92.19.100])
	(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 <internals@lists.php.net>; Sat, 22 Feb 2020 18:01:50 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=YhrgWElC2ObJezu0Fq0ZNYl+S6fKySxOEDGGmK+qXS+Z8ZHLMqAFWnECDgJXwsGgx86WdXetyI3H06aJPoTmPjlwWyaM0Rs+ZYmvruP3sQuxdoQ69b/Tgn27zwFIlBY1H4eS4Zx1I3Bh7cMMgDjGJ2BqHOo7hIi0qqgHi+p3Jrauszhzk5ApLflZnyDIveHlzECdJ31sDtOMKjYXkI4O/Ao2BbaDL25e4QGDjiGJfZtWZQjzH7ZQSv9a0+DX1c5AOMrNu9iMkWdR+tf2oM/AEdPYoU8kJHCSCfjPXLepy05oyAgBbKRemEcnqMTdUFXKjvxw7qclNk31KiCnamzbAw==
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=9p9xjvNibN5MasIFG6OWOQTli9VRXeydCAd8H61+lVI=;
 b=XYGhwZeQAb4bQvNkV1/8KOpqklGfAiR1cpHUqoGWmXk0xjgc17nqOpY+CYpgHWCnm1qKl9BKzcFPfRRXDIZQzoWJVGmni4q8DR0N4aAFDpXoUmjMTUd5ROusDSUqok9OOBwymnK5gVTa/Kgo4MYoP+wyU8IfSB2rVyJUUNBxLdalL0PNJpELSWeAJsjyZv4uiGCjYgrVYE766kj/ZramGrc7aHSS47q1xyaXPcUtNRie+TFnfvg02rmoQn7q/QWKEmg22iMkxvxCDIT9X0nWDRnu1PbsGPulemyX1EPv4J1Q6rvAC/YlYCaR3I/JxLPjI8wVuqvqq/KjQ9d2KgVOSg==
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=9p9xjvNibN5MasIFG6OWOQTli9VRXeydCAd8H61+lVI=;
 b=ZB/tdcL6+nLK4ETnNPnzt+sltiGp2SrMhSLk6uot2ORVU/mhO+pct2MUgZEaocETM4PNe2giYM8eA00zGfbBrx8C6XIp84wY8V+J3sGI9Eqn5TlEIw6R31rVHG7NFu6ttfEgqBITKvcP8gITiC1BzbrkacUdEkYZpKpH8ab8zNB3uvRJZ77UDYBKgrcHoeikvJz7QMfQhHVspWA6M4nv0gxvXqnYAUmR4Knv9sloNKL0JEVEfNhFFZfugqtLxsSHxviSeqrNU6jPJ7yNw8FPEy0hW/kW8umeNq6xp2IFGkMrkt16KVDrFjGf+eMlyT9Jxa5lBufCnzEccjBsO5bDmw==
Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com
 (2a01:111:e400:fc4b::37) by
 BN8NAM11HT216.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::169)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.18; Sun, 23 Feb
 2020 02:01:49 +0000
Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.176.54) by
 BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.2750.18 via Frontend Transport; Sun, 23 Feb 2020 02:01:49 +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.2750.021; Sun, 23 Feb 2020
 02:01:49 +0000
To: Bishop Bettini <bishop@php.net>
CC: "internals@lists.php.net" <internals@lists.php.net>
Thread-Topic: [PHP-DEV] Re: Straw poll: Places to allow function calls in
 constant expressions
Thread-Index: AQHV5TVGaQlwvBZF+k68DGwMXa9nx6gi0ZiqgAARpgCABSS0Fg==
Date: Sun, 23 Feb 2020 02:01:49 +0000
Message-ID:
 <DM5PR07MB3067AD9AEA2BCB151677F90DF9EF0@DM5PR07MB3067.namprd07.prod.outlook.com>
References:
 <CY4PR07MB306346D5C035C0BE8AB30195F9160@CY4PR07MB3063.namprd07.prod.outlook.com>
 <DM5PR07MB306731B6D06285C5E936B5FFF9100@DM5PR07MB3067.namprd07.prod.outlook.com>,<CAEYWF=4XFoE8UTkOiZjpJqd+6+9YjShNjFuUKpAPJT4qnqwu+A@mail.gmail.com>
In-Reply-To:
 <CAEYWF=4XFoE8UTkOiZjpJqd+6+9YjShNjFuUKpAPJT4qnqwu+A@mail.gmail.com>
Accept-Language: en-CA, en-US
Content-Language: en-CA
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-incomingtopheadermarker:
 OriginalChecksum:FB0213BBB894FA02215CB41CAA0DD65875D355C051A49E726C5C7B9607A2DAD5;UpperCasedChecksum:8E4B0D0B8ACFE537C008A31C20F1816D300EAC447459CB89AD84924654540BE1;SizeAsReceived:7374;Count:46
x-ms-exchange-messagesentrepresentingtype: 1
x-tmn: [Q7U4QUMxhSarxLjfe13kkVlS2YlTv5Tv1xwZ8V5Da8BcQk4stkkz2wbUbRPom9Bx]
x-ms-publictraffictype: Email
x-incomingheadercount: 46
x-eopattributedmessage: 0
x-ms-office365-filtering-correlation-id: aca1f479-dd01-44a7-4ff7-08d7b8045847
x-ms-traffictypediagnostic: BN8NAM11HT216:
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info:
 fYSjRn3THwjyV1nGy79Qe6S2raX7ncsuiru6bJO8Ho1idLYHaPvKlMXr/GSh6GEW+yL1rRwgX2Phy/GQe0ZK6ibyBDyg0ZxiDPvWTNfeyLqHCBrd8pz2KvYnAIJhJuoee3WmA/O71Rs7hP0ilToDeobKJKbb6bzqYPDPHXxqk2W0M4M/JhK1W6bOSPcl1Sr3Bp1kUlzkQZXqSCQjHmrzrkLlBBpTFXcEcWc3rtNL/Bk=
x-ms-exchange-antispam-messagedata:
 KAvvjdd2ylTWx+t+M7S+8c1BU1cnwvQuxtdSZADfBu3lPCJYfgSiZvzdzb+RyykCFANJSiNO3X/v0uTD/PpRnxsyvfbYCxStWZ954TP7+3ojrdyuP7cisF92oi9n6wAqdxJcWY43OyORpmcGBq/K0tuXxnMrSsNJP6EgfS0PJwKAzvE4Dbuv21oG4u76j8H2kIum7YqbvFahjd+ihOVS/Q==
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: aca1f479-dd01-44a7-4ff7-08d7b8045847
X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Feb 2020 02:01:49.6293
 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Internet
X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM11HT216
Subject: Re: [PHP-DEV] Re: Straw poll: Places to allow function calls in
 constant expressions
From: tysonandre775@hotmail.com (tyson andre)

> The original motivation was, IIRC, to initialize class constants with an =
expression.=0A=
> Following KISS, I feel we should constrain our efforts to that scope, and=
 that's how I voted:=0A=
> "Yes" on class constants and static members, "No" on everything else.=0A=
=0A=
I'd also personally found the `static $x =3D null; if ($x =3D=3D=3D null) {=
 $x =3D some_fn(); }` pattern inconvenient and wanted that to be just `stat=
ic $x =3D some_fn();` to make the initial value `some_fn()` if possible. It=
 also seemed more readable (e.g. doesn't matter if some_fn() can be constan=
t).=0A=
=0A=
My personal use case for parameter defaults and global constants isn't as s=
trong (especially with define()),=0A=
but it's still something I'd want.=0A=
=0A=
- I'd be able to use `private const FOO_DEFAULT =3D array_keys(...); functi=
on foo($x =3D FOO_DEFAULT) {}` if constants did pass, so that's less off a =
concern, and ensures&makes clear that the expression is only evaluated once=
, so it might be a better place to start with.=0A=
=0A=
> As for implementation, we must manage the complexity.=0A=
> I'm a hard "No" on restricting use to an arbitrary, variable list of bles=
sed functions.=0A=
> It's a dev UX nightmare to include a bevy of array_* functions but no str=
* functions.=0A=
=0A=
If the RFC succeeded with a whitelist, I'd planned to create RFCs to add to=
 the whitelist.=0A=
Locale dependency of string functions was the reason for leaving it out ini=
tially, since that may also be a hard "no" for others.=0A=
=0A=
> Consequently, the only way to safely initialize class constants and stati=
c members is at run-time, and I can only think of one way to do it.=0A=
> Apologies if this has already been suggested: taking a cue from C#, a sta=
tic class constructor ([1]) =0A=
> would allow us to have expression-initialized constants and static member=
s.=0A=
> <?php=0A=
> class Config {=0A=
>     public const URL =3D null; // compile time initialization=0A=
>     protected static $mtime =3D null; // compile time initialization=0A=
>     private static function __constructStatic() {=0A=
>         $env =3D json_decode(file_get_contents('config.json'));=0A=
>         self::URL =3D $env->url;=0A=
>         self::$mtime =3D filemtime('config.json');=0A=
>    }=0A=
>    public function reload() {=0A=
>        if (self::$mtime < filemtime('config.json'))=0A=
>            self::__constructStatic();=0A=
>        }=0A=
>    }=0A=
> }=0A=
> =0A=
> echo Config::URL; // assert: runtime has already called _constructStatic=
=0A=
> $config =3D new Config; // assert: __constructStatic called only once by =
runtime=0A=
> $config->reload(); // instance may call its own static constructor=0A=
?>=0A=
=0A=
This seems to allow the same functionality my RFC would allow, in a slightl=
y different way.=0A=
I didn't go with that syntax because it'd move the values of the constants/=
properties away from the declaration.=0A=
Also, if `json_decode()` threw, then there would never be a way for a PHP i=
mplementation to initialize `self::$mtime` in that example, even though the=
y're unrelated in how they're initialized there.=0A=
Allowing calling `__constructStatic` multiple times (thus assigning to the =
**const** `self::URL` multiple times) would be a significant change to php =
internals, and out of the scope of this RFC=0A=
=0A=
https://wiki.php.net/rfc/calls_in_constant_expressions_poll ("Put the RFC(P=
oll) URL into all your replies.")=0A=
=0A=
- Tyson=