On Wed, Jun 16, 2021 at 11:17 AM Nikita Popov <nikita....@gmail.com> wrote:

>
>
> The options where static properties and class constants are concerned are:
>
> 1. Eagerly evaluate initializers on declaration. This is what I tried in an
> earlier revision of the RFC, and I don't think that approach works. It
> breaks existing code and has various other unpleasant complications.
> 2. Precisely specify the current behavior. I don't want to do this either,
> because the exact places where evaluation happens are something of an
> implementation detail. If in the future we find it convenient to separate
> evaluation of non-static properties on object instantiation from evaluation
> of static properties and class constants (which are not strictly needed at
> that point), I'd like to retain the liberty to make such a change.
> 3. Do not specify an evaluation order, beyond that evaluation happens at
> certain uses of the class. Evaluation order may change across PHP versions.
> If your code relies on any particular order, your code is broken.
>
> Unless I'm missing a fourth option here, option 3 is the only one I would
> be willing to go for at this time.
>

I think I was one of the people that came up on the mailing list with the
idea that it would be good to have the order of evaluating the initializers
clarified in the specifications.
Little did I know at that time how constants are "evaluated" until now.

I watched the topic and comments you added few months ago on the PR while
you were doing the implementation and got into trouble with preloading that
really can't work nicely with eager initialization.
I didn't say anything at that point but my ideas went towards option 3 as
well, specifying that the evaluation order is not well determined and can
change in the future so I agree with others here.

It's not the first time this happens in PHP (https://3v4l.org/fQhgB) and I
think we will be fine with it.

Alex

Reply via email to