Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107979 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69160 invoked from network); 3 Jan 2020 18:49:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2020 18:49:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 657341805BB for ; Fri, 3 Jan 2020 08:53:31 -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=-0.7 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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, 3 Jan 2020 08:53:31 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0F49B21C1E for ; Fri, 3 Jan 2020 11:53:31 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Fri, 03 Jan 2020 11:53:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=XOqUfMHbHUbXJHblx5165dxTB4GvxSgT1fdTh60TV u0=; b=anHpdWaxKcM8i4+3bEjn50IHG+f/HYQLnLXIkPTcHwGUr+6W6Wk8xkr6j Ddw63qYz5inksoYUPnc5IntUT/sF4p1/BufV1RwRHaM1jy1ZXi17SQuw3fLyfIMA JlF/OuWyDpgFc0lS65QPZIJtx+c08iBp2nY90mo3SiYvNnnlF73ikmxDfM6LKRrl 10mg2Z3Jnn/PQA+04QV4i6YmKOKH5dSZGpjVw0xmW5PJ0L+NZls2UZuCqTnP5YNy MuJ1MGb9Trz4CKyzuYgk9DUvqnkmDVdmXonh8lvvca14TQ4hEwjQ4hllTQNyDNlj L1XOAF4kkukqvC4CsZRfWkK60gV1Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlught vggthhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id B447914200A2; Fri, 3 Jan 2020 11:53:30 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-694-gd5bab98-fmstable-20191218v1 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> Date: Fri, 03 Jan 2020 10:53:09 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Initializing constants once, with code? From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jan 2, 2020, at 6:39 PM, Mike Schinkel wrote: > > On Jan 2, 2020, at 7:09 PM, tyson andre = wrote: > >=20 > >> The problem with using constants is that the value is still hardcod= ed > >> and if we later want to change to pulling the data from a config fi= le=20 > >> we have to change all the code that uses those constants.=20 > >=20 > > It's possible to work around this by using a unique constant name > > and define('unique_name', $dynamicExpression) > > (and const MY_CLASS_CONST =3D \unique_name;) >=20 > I do appreciate the attempt to come up with something that is a workar= ound. >=20 > That said, I definitely do not want to do is start using "clever" code= =20 > in my implementations because =E2=80=94 one day =E2=80=94 someone else= will have to=20 > maintain what I write. >=20 > Really, I was just asking for a discussion of potentially allowing for= =20 > one-time initialization via code for constants and via a=20 > straightforward, obvious syntax and standardized syntax. =20 >=20 > Effectively I am just asking for immutable static values in a class=20= > that can be access vis the :: syntax. >=20 > -Mike I agree with the use case, but not with the solution of piggybacking the= m onto constants. It seems to me it would be much cleaner to just... bu= ild that into a static method call with the derivation-and-caching logic= behind the scenes. It's not complicated code. class Stuff { protected $val; public static function val() { self::$val ??=3D computeStuff(); return self::$val; } } Although property accessors might make it even nicer looking, if we can = ever figure out how to make that performant. :-) --Larry Garfield