Re: Constants and Access Modifiers
| From: | lists@rhsoft.net | Date: | Sun, 12 Nov 2017 19:00:52 +0000 |
| Subject: | Re: Constants and Access Modifiers | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101131@lists.php.net to get a copy of this message | ||
Am 12.11.2017 um 19:25 schrieb Rowan Collins:
On 12/11/2017 09:49, Fleshgrinder wrote:There is one thing that differs for the const and the field: a const value must be known at compile time, whereas a field value does not. An important difference!What I'm not really clear on is *why* the value being known at compile-time is important to you. Is there some architectural decision you would make differently based on this guarantee? Are you expecting the language itself to have some optimisation or different behaviour based on that guarantee? compile time at least leaves space for optimization and looking what opcache only since PHP7.0 got and looking forward to a JIT implementation this can make a difference in the futureclass A { abstract public const FOO: int; } class A { abstract public function foo(): int; }These also look basically the same. The return value of the method, however, may also be determined at runtime (just like with fields) and on top of that might change with every invocation.