Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114089 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81073 invoked from network); 21 Apr 2021 15:56:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2021 15:56:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 292931804DC for ; Wed, 21 Apr 2021 08:59:43 -0700 (PDT) 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.0 required=5.0 tests=BAYES_20,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 21 Apr 2021 08:59:42 -0700 (PDT) Received: from wafer.home (unknown [IPv6:2a02:1205:5053:a220:8c69:518:f16c:47fa]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 471FD150D06F for ; Wed, 21 Apr 2021 17:59:40 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Date: Wed, 21 Apr 2021 17:59:39 +0200 References: <004701d73549$6dbc9840$4935c8c0$@jhdxr.com> <00c501d7368e$922938f0$b67baad0$@jhdxr.com> <866BBB78-85D0-4C97-87FC-63E526CDDF9F@cschneid.com> To: PHP Internals List In-Reply-To: Message-ID: <1DAB151B-685B-49B1-9B81-3D61F6B8955F@cschneid.com> X-Mailer: Apple Mail (2.3654.60.0.2.21) Subject: Re: [PHP-DEV] [RFC] [Draft] Final constants From: cschneid@cschneid.com (Christian Schneider) Am 21.04.2021 um 17:08 schrieb Andreas Leathley : > On 21.04.21 15:14, Christian Schneider wrote: >> I never really understood the desire to restrict how people can use >> your code. >> If there is no good reason to override the value of a class constant = people won't do it. >> If there might be a good reason (even one you as the original = designer didn't predict) then why not leave that door open. >>=20 >> While I understand the theoretical benefit of being able to specify = this behavior I do think it is almost always counter productive and not = a pattern I would encourage. Especially not in a dynamic language like = PHP. >=20 > Such restrictions also convey information and intent. One could argue > defining a specific return type to a method is restricting its use, = but > it also clarifies how something should work and avoids unintended > changes. To me, the term 'constant' is good enough for that... > final constants might be more niche, but it gives you a choice > on how you want a class constant to behave if child classes are > necessary and possibly done by someone else. ... but if child classes are necessary then how can you say that the = constant's value should never be different for children? Why not leave that to the user of your class? I've seen my share of = damage done by assumptions about how code will be used later. > Having "final" for constants seems a good addition to me, especially = if > the inconsistent behavior with interface constants can be solved at = the > same time. Fixing this inconsistency should be discussed separately IMHO. Both = because it is a side-effect and should not be used as a reason to add = 'final' as well as not fixing the problem for code *not* using 'final' = with constants. Side-note: Back in my Java days people argued with performance to add = 'final' but that only lead to it being sprinkled all over the place = making code less flexible than it needed to be without real performance = benefit. That's what I mean by promoting harmful patterns. - Chris