Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101068 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33995 invoked from network); 6 Nov 2017 00:44:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2017 00:44:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.179 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.179 mail-pf0-f179.google.com Received: from [209.85.192.179] ([209.85.192.179:48967] helo=mail-pf0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/88-09857-460BFF95 for ; Sun, 05 Nov 2017 19:44:22 -0500 Received: by mail-pf0-f179.google.com with SMTP id b79so6462321pfk.5 for ; Sun, 05 Nov 2017 16:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=QGAIkx/CTLoBrlUW/WC3uIpE0ls2GI6AbPs9bL14xfQ=; b=flCnxX6ARifEVhOFn2OQDpLZbRcAZ3PqjtjAjaLBNIYfl3sp9Zciy5aqb1swPGUv9Q KN3LWUVpz6HVd6T0WfCZ/6ru+uPV6Am1d4hBV0K7UVZimbt853mEX98L//+4/qNC87cy kijiH9abRbUbrud1i4r++j2L4uhsB4IQNSEnXI6irie5cUxGmXLwIH/G7I6P8BwKmxZZ 8v4x7hImLOkV8oDlvGjE3Z+yOIgSLY4DT9iTuPV4l5doDh5b0Hpg/dl1kqw9NrlSlSpP dabr9qMqcFchbVw2bh4XT8pa9HcY6EzdHVz9Ce8WPszp55RMuorE3uzB00m5MNq8PyTZ I7gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QGAIkx/CTLoBrlUW/WC3uIpE0ls2GI6AbPs9bL14xfQ=; b=Yku7jnB3e9gq0E/5uvMcGmfz2WiNzV0vhffReWi+qgnWqBJ3zI1WjAh9o8FJUbZBfj 8wgwNgqy6F9Dh7YAfoZjltVoZ33XjAc9QoajRoaxXgEK+mYH+ZNqqFfb0hV2wXh4+Nms s145MIJK797svnPSFO2xLduKQAqCEXqOiLg1GUDZN2B/mZgH3Z+nWR5lVCcGuTAqgsoU CsIPtG+a70uqSxV+BQci+vP7fqLAGe96xDLY4x19APdErH0XyltB0rd6j8kkLDtVaWlr 6AMbtc2nINvlubsmU2mP+BGYa0ZYmkZYZQHtPR1q95nye7auYnXSuuDGz68sBDrVpoZq bB2Q== X-Gm-Message-State: AMCzsaWaIacIs5JhQPl6h3QwHLsEox834MzQH5IQ0Yls/1ZKNBdIBbxN kJnjsk3k+JYePzFtvhZlGA== X-Google-Smtp-Source: ABhQp+R2kpnuRU+PQEHbJM3hjA8np7gpkAZDhnh6Y7tiO6l6JwSOqmFeqpHiUHBhN5yZaV+KwC8KQw== X-Received: by 10.101.76.139 with SMTP id m11mr13953484pgt.103.1509929057117; Sun, 05 Nov 2017 16:44:17 -0800 (PST) Received: from Stas-Pro-2016.lan (c-73-71-144-171.hsd1.ca.comcast.net. [73.71.144.171]) by smtp.gmail.com with ESMTPSA id j6sm17948241pgn.68.2017.11.05.16.44.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Nov 2017 16:44:16 -0800 (PST) To: 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: Date: Sun, 5 Nov 2017 16:44:15 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <0061a0c9-328c-75cb-cf6f-8e444e9ea3c0@fleshgrinder.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Constants and Access Modifiers From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > 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. It's not a constant then, and should be a method. > > The thing is that I want something that CANNOT CHANGE. I want to require 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 :) > 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 = \PHP_INT_MAX; > public const MIN = \PHP_INT_MIN; > } > > class WholeNumber extends Integer { > public const MIN = 0; > } > > class NaturalNumber extends WholeNumber { > public const MIN = 1; > } Integer::MIN and NaturalNumber::MIN are different constants. So, it is natural that they can have different values. Though using constants with these names is slightly misleading, but if you always use full name, not by much. > 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). 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 modelling - inheritance is not just shortcut for avoiding copy-paste. > 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 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. -- Stas Malyshev smalyshev@gmail.com