Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101122 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35947 invoked from network); 11 Nov 2017 18:39:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2017 18:39:38 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.89 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.89 mx108.easyname.com Received: from [77.244.243.89] ([77.244.243.89:55017] helo=mx108.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/17-15386-7E3470A5 for ; Sat, 11 Nov 2017 13:39:37 -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 1eDagk-00014c-FF; Sat, 11 Nov 2017 18:39:32 +0000 Reply-To: internals@lists.php.net To: Stanislav Malyshev , internals@lists.php.net, Niklas Keller Cc: Nikita Popov References: <93a05192-ed34-2164-50f9-2799899b32d1@fleshgrinder.com> <4ee3d414-92e1-75c7-402f-16a37ed3016b@fleshgrinder.com> <3f093ce2-e00e-f210-6e35-de31eb2f4b07@gmail.com> <0061a0c9-328c-75cb-cf6f-8e444e9ea3c0@fleshgrinder.com> Message-ID: <2f555141-96e0-3bab-c191-1216747644a5@fleshgrinder.com> Date: Sat, 11 Nov 2017 19:39:18 +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="3fFb8SD8pgS8mVlkocuE0i73IknvmkP76" X-DNSBL-PBLSPAMHAUS: YES X-DNSBL-SPAMRATS: YES Subject: Re: [PHP-DEV] Constants and Access Modifiers From: php@fleshgrinder.com (Fleshgrinder) --3fFb8SD8pgS8mVlkocuE0i73IknvmkP76 Content-Type: multipart/mixed; boundary="qhDojdx5DCdWEmT9ak4VO3QQ4Ud9uMIDL"; protected-headers="v1" From: Fleshgrinder Reply-To: internals@lists.php.net To: Stanislav Malyshev , internals@lists.php.net, Niklas Keller Cc: Nikita Popov Message-ID: <2f555141-96e0-3bab-c191-1216747644a5@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> <0061a0c9-328c-75cb-cf6f-8e444e9ea3c0@fleshgrinder.com> In-Reply-To: --qhDojdx5DCdWEmT9ak4VO3QQ4Ud9uMIDL Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: > Hi! >=20 >> An abstract constant is a constant that requires its value to be defin= ed >> later, like an abstract method that requires its implementation to be >> defined later. >=20 > It's not a constant then, and should be a method. >=20 No, because a method can change what it returns, it is not constant. On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: >> >> The thing is that I want something that CANNOT CHANGE. I want to requi= re >=20 > You are contradicting yourself. If it is not known upfront, then it can= > change - otherwise, you'd know it upfront. I'm not sure what you're > trying to do here, but I am getting pretty sure you shouldn't be doing > it with const's :) >=20 No, I want to split the definition and initialization. The value cannot change, once it is initialized. On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: >> Dropping support for constant inheritance is imho also wrong from a pu= re >> 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; >> } >=20 > Integer::MIN and NaturalNumber::MIN are different constants. So, it is > natural that they can have different values. Though using constants wit= h > these names is slightly misleading, but if you always use full name, no= t > by much. >=20 I do not follow, what is misleading about them? Referencing them without the full name is also not possible in PHP, hence, not an issue. On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: >> does, simply because it is a different value. Of course we expect it t= o >> be compatible, they are after all in a tight relationship (inheritance= ). >=20 > Here you are getting into a dangerous territory, btw. Depending on your= > modeling needs, of course, but your NaturalNumber can violate contract > of Integer, such as "being able to represent -10". Thus, inheritance > could be wrong way to do it, at least in the way you described above. > One has to be very careful with which exactly contract are you modellin= g > - inheritance is not just shortcut for avoiding copy-paste. >=20 I am not sure how you deduce that NaturalNumber can be -10. There are not invariants defined anywhere on the classes. You are correct that inheritance should not be misused for code reuse, it should be used to build type systems. Which is exactly what I am doing in the example. On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: >> 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 t= o >> broaden your views on the topic: >> >> https://news.dartlang.org/2012/06/const-static-final-oh-my.html >=20 > From this link, it looks like const in Dart has pretty much nothing in > common with const in PHP, besides name, so in the interest of avoiding > confusion, I would not discuss it in the same topic. >=20 Yes, Dart has a different understanding of const, which is exactly why I posted it for you guys. In the hope that it helps to get more different views on the topic. Currently you are too concentrated on how it is implemented in PHP at this time, and argue that it is impossible to diverge from that path. Which is simply not true, we only have to ensure backwards compatibility. --=20 Richard "Fleshgrinder" Fussenegger --qhDojdx5DCdWEmT9ak4VO3QQ4Ud9uMIDL-- --3fFb8SD8pgS8mVlkocuE0i73IknvmkP76 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 iQIcBAEBCAAGBQJaB0PgAAoJEOKkKcqFPVVru+IP/iAIy3X75vnTpl1z62yVvSc/ DR8QLRqN0WafqnLyjeSU5Z904VIKSgQZLcPmm/Z8O4F7WbsfqivJLEiEqpEv8y/F nmuE82DEetpQSomUMSDw4bf0LlCP6CCw/sAP/VAVoH7Fm2bkWT1Pi3YhsvVjwxKK PmenRQQvGMd2XPFBxc+QMU0d87LJnLBvha3DqI+lca/uPJY7mrGXis+xbdbiVOC0 3ecMRRv0uVk3Nu7LCpJ9Et5NL0sOBzK/AqytA9uKzRQVtq5zoai1uGO/G2zNHtZx nSHYGzscZgOscmV6sLUyg/sn+2BqCSpXRZ1slgZoBzKW5Ft3MSLjb83T1vmRPx6r bRMbW6UK2i6vgvy/oekrIIbwNryLCB+/KPaPopWUb+shwOnDAusjKEzo3gGMZ7M+ HyMgvo8wbd/TPH1UZCqdgePwqsUlwshcWTYh9x1SsKZty+741NsdDwz7o+/pcHfB nU89yBxgaqcS7jPJh9hcCtp0lnWrGoA7L/wcjZ9lOBgqyzvosdn0XChbaC9lEZKY hxKRLMlZQyfMh6zQJw7zc7+zO+EQa6Ys4ydyHmVYDuBmxXZSfmwdG9+0jqrWo6mC vLxAKwg7LMml+n9w/YVRZtIU6FTsPcztWh8tUnqKGxL0rWQT/Lk+raTpDBXUjCfu oftRumYiXSdT/2lqX13K =uLh7 -----END PGP SIGNATURE----- --3fFb8SD8pgS8mVlkocuE0i73IknvmkP76--