Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:114078
Return-Path: <me@jhdxr.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 78804 invoked from network); 19 Apr 2021 18:23:51 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 19 Apr 2021 18:23:51 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 8124E1804C6
	for <internals@lists.php.net>; Mon, 19 Apr 2021 11:26:02 -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.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO,
	FROM_EXCESS_BASE64,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,
	UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2
X-Spam-Virus: No
X-Envelope-From: <me@jhdxr.com>
Received: from smtpproxy21.qq.com (smtpbg704.qq.com [203.205.195.105])
	(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>; Mon, 19 Apr 2021 11:26:01 -0700 (PDT)
X-QQ-mid:Yeas4t1618856753t167t39798
Received: from 08355B1394674FDAAD07A274D17563B1 (me@jhdxr.com [116.14.113.108])
X-QQ-SSF:00100000000000F0FG1000000000000
To: =?UTF-8?Q?'M=C3=A1t=C3=A9_Kocsis'?= <kocsismate90@gmail.com>,
	"'PHP Internals List'" <internals@lists.php.net>
References: <CAH5C8xVaVtH=SieiObYKAuo2f5jTtuwAZeVB_hyXyw=aQG6a4g@mail.gmail.com>
In-Reply-To: <CAH5C8xVaVtH=SieiObYKAuo2f5jTtuwAZeVB_hyXyw=aQG6a4g@mail.gmail.com>
Date: Tue, 20 Apr 2021 02:25:51 +0800
Message-ID: <004701d73549$6dbc9840$4935c8c0$@jhdxr.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQHi46dfJ12ACkqZRUHCdTGM+mYT6qqkyo3g
Content-Language: en-us
X-QQ-SENDSIZE: 520
Feedback-ID: Yeas:jhdxr.com:qybgforeign:qybgforeign5
X-QQ-Bgrelay: 1
Subject: RE: [PHP-DEV] [RFC] [Draft] Final constants
From: me@jhdxr.com (=?utf-8?b?Q0hVIFpoYW93ZWk=?=)

Hi Mate,

Can I ask why you use late static binding while you don't want your =
constant value to be changed/overridden by child classes? IMHO, =
`self::FOO` is all you need.

Regards,
CHU Zhaowei

-----Original Message-----
From: M=C3=A1t=C3=A9 Kocsis <kocsismate90@gmail.com>=20
Sent: Sunday, April 18, 2021 10:20 PM
To: PHP Internals List <internals@lists.php.net>
Subject: [PHP-DEV] [RFC] [Draft] Final constants

Hi Internals,

I've recently realized that class constant values cannot always be =
trusted when late static binding is involved (e.g. static::FOO or =
$this::FOO), since they can be freely overridden in child classes. =
That's why the engine knows neither the type and the value before =
run-time.

Doctrine coding standards has a specific rule which disallows =
referencing a possibly overridden class constant (
https://github.com/doctrine/coding-standard/blob/8d75920bb04a9be4c73c2a77=
5ee5766262cf2a0d/lib/Doctrine/ruleset.xml#L123
),
but I'm wondering if it would be better to simply make it possible to =
allow declaring class constants final  (thus disallowing overriding) =
instead?

In my opinion, final constants would come with two advantages:
- make class constant declarations paranoidly safe
- allow the engine to optimize class constants references in LSB context

Although I admit that the win is not extra huge, I do think that it =
would still be useful to have this feature, especially considering that =
the implementation is very straightforward ( =
https://github.com/php/php-src/pull/6878). So that's why I'm proposing =
this as an RFC.

Recently, a similar attempt to make class constant declarations safer =
was the Typed Constants RFC =
(https://externals.io/message/110755#110755), but unfortunately it has =
halted since then. I think final and typed constants would be a nice =
little addition, and would complement each other well.

Regards,
M=C3=A1t=C3=A9