Hi

On 3/15/23 18:21, Ilija Tovilo wrote:
https://wiki.php.net/rfc/arbitrary_static_variable_initializers
https://externals.io/message/118976

There is an unresolved "question":

Side note: It's been suggested that expressions that can be evaluated 
constantly continue to do so. This would mean that some expressions in 
getStaticVariables are evaluated and some are not. The upside is that this 
would avoid the backward incompatibility. I will check if this is technically 
feasible.

Ah, thanks for catching this. This has been partially implemented. PHP
will attempt to evaluate the constant expression at compile time. If
successful, the value will continue to be available from
ReflectionFunction::getStaticVariables() right away. Only when the
expression isn't known at compile time (including class constants from
other files) will it contain null until the function is called. This
reduces the BC incompatibility but doesn't completely avoid it.


Using Alain's example of static variables that depend on each other. For the following:

function foo() {
  static $a = 0;
  static $b = $a + 1;
}

The value of '$a' is known at compile time. Is the value of '$b' also known at compile time? It might make sense to include that as an explicit example in the RFC (examples are cheap).

Best regards
Tim Düsterhus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to