Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101123 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42548 invoked from network); 11 Nov 2017 20:51:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2017 20:51:59 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:39125] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/97-15386-DE2670A5 for ; Sat, 11 Nov 2017 15:51:57 -0500 Received: by mail-wm0-f41.google.com with SMTP id l8so2965925wmg.4 for ; Sat, 11 Nov 2017 12:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=g4qcNifjMOWPuT1K7RMcOrjowUZw5MRum97poVqMFZ0=; b=Mk/ZiU7rxtMylXPtZpVsJ3aclkLINL/vgAP9IhZrWID7JwGgLU/hMIm+bfGT2gBwai QZdPSExVdMgedRVJGAGCOEmJ4WpVuZ/BrGmx3otyrD9aYLD4cX6WZiVgJlFJw7SVO6oN tG5CBSFPRFCfNtO47En/NJ2FUQEUP3xDSxWlnjUmdi0A+2s7AjUlIu0AefhXKDSiuutT GaNBhvubpIM9UArQIqEzQvdMUNrG07zHoPiFUXBqTAQdnyxNriDhuXv4D4Z55LZfc9LE e+08bfx5uvfLd6594LQa6Wvrvvu7LJOggpoOuMXUQCBjiX99EQevV6m9q31aUyA8l7Z4 4ZSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=g4qcNifjMOWPuT1K7RMcOrjowUZw5MRum97poVqMFZ0=; b=m40dht+Iy4PK/1HjBYGYIyHO4VF3AnebwZU2DRZ9WD1M1scXs0sGw9u+GLiHaBlk3A 2kBlKrKwePXJIyMoYsWroUc14hGcmTwkx2KeeYCdVT90sT9TjoGbOipOsvl5LVhNvzON NyD3dBYj1ltw22xCsTq6HBYBnTQuKMFgHjyM55sofModIwABSW6Gpj++ZmnCvR4jBpGG ZqTdVP6kUbnFlPQn2HoIcnEJCOmq+O+4qNJ+SOovLiMmh4w/CXjjj5h6ZNTYqYSMXT8N +2ns3P8mzyZpeyixviqDiMcqq+uAj9Qd0J00nS1Js+5rYVzcsM9GYcNmjlSy/SGVJIJ2 aSiw== X-Gm-Message-State: AJaThX4XxBpaQvqu7ODJVg/67cjd0hrg7QAI09lqFsBZ5qBobmPoOBLn ntZ2MrypCrpQB8sMHZzETHHkwg== X-Google-Smtp-Source: AGs4zMb14lpmUD32MeTQcdu6+P/ncwYjymPqskGdyALPd6ZxIZOlE0fwcHB3oPa4/h2YTNFt6GaDcA== X-Received: by 10.28.157.7 with SMTP id g7mr1870384wme.89.1510433513774; Sat, 11 Nov 2017 12:51:53 -0800 (PST) Received: from ?IPv6:2a00:23c4:4b81:ae00:203d:75ca:72de:171d? ([2a00:23c4:4b81:ae00:203d:75ca:72de:171d]) by smtp.googlemail.com with ESMTPSA id r14sm24334728wrb.43.2017.11.11.12.51.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Nov 2017 12:51:52 -0800 (PST) To: internals@lists.php.net 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> <2f555141-96e0-3bab-c191-1216747644a5@fleshgrinder.com> Message-ID: <3b592a4b-c56d-fd16-f977-7c9898fabf57@gmail.com> Date: Sat, 11 Nov 2017 20:51:49 +0000 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: <2f555141-96e0-3bab-c191-1216747644a5@fleshgrinder.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] Constants and Access Modifiers From: rowan.collins@gmail.com (Rowan Collins) On 11/11/2017 18:39, Fleshgrinder wrote: > On 11/6/2017 1:44 AM, Stanislav Malyshev wrote: > >> 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. >> > 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. I think the point is that adding "single-assignment variables" (which Dart calls "final") or "deeply immutable values" (which Dart calls "const") would be a completely different feature which could be added side-by-side with what we have now, under a different name. What PHP calls "const" (in the context of classes) is neither of those features. The debate seems to be whether you view class constants as more like static properties, or static methods. Given this: class A { public const Foo = 42; } echo A::Foo; Is it equivalent to this (using an imaginary "readonly" modifier)... class A { public static readonly $foo = 42; } echo A::$foo; ...or is it equivalent to this (particularly if you imagine an optimising compiler that caches / inlines the result)? class A { public static function foo(): int { return 42; } } echo A::foo(); The difference is that a field is never "abstract" - it either has a value, or it is undefined; you can't add a contract to an interface saying "you must have this field" either. A method, on the other hand, is assumed to encapsulate something - it's a black box with a contract, so defining the contract without any implementation makes sense. (Note that I've called $foo a "field" to distinguish it from a "property", as C# does: a property with a contract like "$foo { public get; private set; }" could indeed be abstract.) The interesting thing about the above examples is that the static method with a fixed return *already works right now*, whereas the readonly field doesn't exist; so it makes some sense to say that "const FOO" is PHP's way of saying "static readonly $FOO", and have it subject to similar semantics. Regards, -- Rowan Collins [IMSoP]