Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101067 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26448 invoked from network); 5 Nov 2017 21:49:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2017 21:49:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.28.122 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.28.122 mx201.easyname.com Received: from [212.232.28.122] ([212.232.28.122:37279] helo=mx201.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/08-09857-C778FF95 for ; Sun, 05 Nov 2017 16:49:49 -0500 Received: from cable-81-173-135-113.netcologne.de ([81.173.135.113] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1eBSnY-0000va-O9; Sun, 05 Nov 2017 21:49:44 +0000 Reply-To: internals@lists.php.net To: Niklas Keller , Stanislav Malyshev Cc: PHP Internals , Nikita Popov References: <93a05192-ed34-2164-50f9-2799899b32d1@fleshgrinder.com> <4ee3d414-92e1-75c7-402f-16a37ed3016b@fleshgrinder.com> <3f093ce2-e00e-f210-6e35-de31eb2f4b07@gmail.com> Message-ID: <0061a0c9-328c-75cb-cf6f-8e444e9ea3c0@fleshgrinder.com> Date: Sun, 5 Nov 2017 22:49:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MUVSPidCdbpPgu7jeEN8WVmR85eqVhiql" X-DNSBL-PBLSPAMHAUS: YES X-DNSBL-SPAMRATS: YES Subject: Re: [PHP-DEV] Constants and Access Modifiers From: php@fleshgrinder.com (Fleshgrinder) --MUVSPidCdbpPgu7jeEN8WVmR85eqVhiql Content-Type: multipart/mixed; boundary="wBxN4r3ihru9XjIxu1EWnC7ErTBgWO1Tw"; protected-headers="v1" From: Fleshgrinder Reply-To: internals@lists.php.net To: Niklas Keller , Stanislav Malyshev Cc: PHP Internals , Nikita Popov Message-ID: <0061a0c9-328c-75cb-cf6f-8e444e9ea3c0@fleshgrinder.com> Subject: Re: [PHP-DEV] Constants and Access Modifiers References: <93a05192-ed34-2164-50f9-2799899b32d1@fleshgrinder.com> <4ee3d414-92e1-75c7-402f-16a37ed3016b@fleshgrinder.com> <3f093ce2-e00e-f210-6e35-de31eb2f4b07@gmail.com> In-Reply-To: --wBxN4r3ihru9XjIxu1EWnC7ErTBgWO1Tw Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 11/5/2017 1:03 PM, Niklas Keller wrote: >> >> Hi! >> >>> My wording was maybe a bit wrong here, and I was biased by the fact t= hat >>> I would like to see abstract constants. The fact that not everything = can >> >> What is "abstract constant"? If you need something that can change, ju= st >> use a method. Constant is meant to be a nice way to write something >> inherently constant, such as instead of "/very long >> (and+)cubmber|some?*regexp/" you'd write NICE_REGEXP_CONSTANT. But it'= s >> not supposed to create parallel inheritance structure or something. If= >> it needs to be non-constant, just use a method. >> >=20 > Totally agree with that. We should deprecate constant inheritance inste= ad. >=20 > Regards, Niklas >=20 An abstract constant is a constant that requires its value to be defined later, like an abstract method that requires its implementation to be defined later. The thing is that I want something that CANNOT CHANGE. I want to require that you define the value, a value that is known at compile time, a value that is immutable, a value that can never changes during the program's execution. This is not achievable by current, available means. What you describe is the intention of the current class constant implementation of PHP, and some other languages. Pure logic does not support this claim. The only thing a constant should provide is that its value is known at compile time. That being said, we already violate that by supporting dynamic constant definitions via define, but let's not go down that road here. Dropping support for constant inheritance is imho also wrong from a pure logical point of view, since a constant's value is only constant if I refer to the very same constant. Meaning, the value of a constant in a subclass must not be the same value as the value in the superclass. class Integer extends Number { public const MAX =3D \PHP_INT_MAX; public const MIN =3D \PHP_INT_MIN; } class WholeNumber extends Integer { public const MIN =3D 0; } class NaturalNumber extends WholeNumber { public const MIN =3D 1; } We expect that `Integer::MIN` always yields the same value, rightly so, since it is a constant. However, nobody expects that `NaturalNumber::MIN` is going to yield the same value as `Integer::MIN` does, simply because it is a different value. Of course we expect it to be compatible, they are after all in a tight relationship (inheritance). They also have to be compatible to each other, otherwise we would violate the substitutability. I mentioned Dart in the initial message, they have a much richer understanding of const than we have it in PHP. Maybe this also helps to broaden your views on the topic: https://news.dartlang.org/2012/06/const-static-final-oh-my.html --=20 Richard "Fleshgrinder" Fussenegger --wBxN4r3ihru9XjIxu1EWnC7ErTBgWO1Tw-- --MUVSPidCdbpPgu7jeEN8WVmR85eqVhiql Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZ/4dvAAoJEOKkKcqFPVVrREAP/0pNxHFn+RKNC+xbRFLD+l9r zBNqPSEJZxlNaodJzwuzkj6Gj7TxcvjTXErvVIII0lis6IA44n0FmxBvH+9vrT+t g1jrfGIW37V7IUbV07p8ygQtQkNgI5ebGH7iZNq/rfPiPQvLNQCrYfJTyd9RtdHB jEr/vVTCVdsTF6x+QsW5UvCO5iLGIXibCm0XMneG9hZ7OmyCAXO6UK/nSoH3B1EH SbWjf1ZREeQl/EXwa5BArkgIJcnQrb/AXfqOOQG+wOlIrgDQzHh5Si62K13LGCuX Yxh2EkDQfASIQaPkDtU5RONeKVQdPKiKupw5XIi3ofeyhbB7FDo0FjiYoTF3QbCj XJUOGT7ddq/3tpKKfh/FrcqMFYL/buvY6ZBMeteiZ7IbcHRdyWrU9URclDbkA7eV wMciACbC5RHudbRbFXoe89aBdAioia0cJQfCd39oPHGWzgpWOPehd/ntfR5USgBy cQ/pzzn9U+WatcngPLAQemEF413BpzuOLSe1ACzR8nqdg2bU5pBginqh0p3aiGE2 wnDE68+uxaaq4ig9SehUSuaaac3tJWbvYRq1tTgv3xcKrEevyGwJ6XKJgA95mE6W kk3If79KoX+LVJv/gFVJVdrzlJpIJUE5SrpyEr0K0Itwv8I6xtKcjGgbFRO9sNAH B8PdHlMD5TYczbGvLJHa =DYlp -----END PGP SIGNATURE----- --MUVSPidCdbpPgu7jeEN8WVmR85eqVhiql--