> Le 19 mars 2021 à 12:22, Nikita Popov <[email protected]
> <mailto:[email protected]>> a écrit :
>
> I've updated the RFC (and implementation) to evaluate class constants and
> static properties at time of class declaration. As such, everything should
> have a well-defined evaluation order now.
>
> However, this also means that this RFC now also contains a
> backwards-compatibility break: Anything used inside class constant / static
> property initializers needs to actually be available at the time the class
> is declared. You can't first declare the class, then declare some
> additional constants it uses, and then use it.
>
I don’t like having the static property initialisers and constants evaluated
eagerly. I typically declare the main class followed by zero or more class
helpers in the same file: with the proposed semantics, I may be forced to
occasionally reorder my code. One particular case I have in mind is the
following refactoring that I may perform with the advent of enums:
```php
class Foo {
const STATE_OPEN = 1;
const STATE_CLOSE = 2;
function setState(int $state) {
// ....
}
}
```
into:
```php
class Foo {
#[\Deprecated] const STATE_OPEN = FooState::OPEN;
#[\Deprecated] const STATE_CLOSE = FooState::CLOSE;
function setState(FooState $state) {
// ....
}
}
enum FooState {
case OPEN;
case CLOSE;
}
```
—Claude