Re: Constants and Access Modifiers
| From: | Fleshgrinder | Date: | Sat, 28 Oct 2017 07:56:44 +0000 |
| Subject: | Re: Constants and Access Modifiers | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100975@lists.php.net to get a copy of this message | ||
On 10/27/2017 11:15 PM, Nikita Popov wrote:
> PHP does not permit self-referencing constants.
>
> However, this is only checked when the constant is first accessed. In your
> first example the constant is never accessed, so no error is thrown. This
> has nothing to do with subclasses defining the value -- you're using late
> static binding, so you're accessing the constant of the child class
> directly.
>
> PHP cannot detect self-referencing constants during compilation, because
> they may be formed through non-trivial cycles involving multiple constants,
> across multiple files.
>
> Nikita
>
My wording was maybe a bit wrong here, and I was biased by the fact that
I would like to see abstract constants. The fact that not everything can
be detected at compile time, but only later at runtime is normal in a
highly dynamic language like PHP. Self-referencing constants make no
sense, hence, it is fine. It would of course be better if the compiler
could detect that earlier, but we are not doing AOT so imho that is
fine. The behavior here is also consistent among versions as well as
HHVM, all good.
What do you think about the other ideas I raised?
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc