Re: [RFC][Vote announcement] Arbitrary static variable initializers
| From: | Ilija Tovilo | Date: | Wed, 15 Mar 2023 17:17:54 +0000 |
| Subject: | Re: [RFC][Vote announcement] Arbitrary static variable initializers | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119711@lists.php.net to get a copy of this message | ||
Hi Alain
> >
> > https://wiki.php.net/rfc/arbitrary_static_variable_initializers
> > https://externals.io/message/118976
>
> Could I suggest that you make something like the following throw an error:
>
> function foo($i) {
> static $a = $b + 1;
> static $b = $i;
> }
>
> You could try to reorder but what if the second static had been:
>
> static $b = $i + $a;
>
> Yes: stupid, but someone will try it.
With this RFC static variables are evaluated in the normal order of
execution. The first statement will throw an undefined variable
warning and result in 1. The second one will be initialized to
whatever $i contains. This is consistent with non-static variables.
Ilija