rfc:arbitrary_static_variable_initializers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:arbitrary_static_variable_initializers [2022/11/07 19:41] – Fix typo theodorejb | rfc:arbitrary_static_variable_initializers [2023/03/16 11:07] – Fix reflection example ilutov | ||
---|---|---|---|
Line 85: | Line 85: | ||
==== ReflectionFunction:: | ==== ReflectionFunction:: | ||
- | < | + | < |
current values. Currently, PHP automatically evaluates the underlying constant expression and initializes the static | current values. Currently, PHP automatically evaluates the underlying constant expression and initializes the static | ||
- | variable if the function has never been called, since the initializer cannot depend on any runtime values of the | + | variable if the function has never been called. |
- | function. This is no longer possible | + | on values that are only known at runtime. Instead, the compiler will //attempt// to resolve the constant expression at |
- | < | + | compile time. If successful, the value will be embedded in the static variables table. Otherwise it will be initialized |
- | and assigning to the static | + | to < |
+ | be reflectable | ||
<code php> | <code php> | ||
Line 104: | Line 105: | ||
foo(2); | foo(2); | ||
var_dump((new ReflectionFunction(' | var_dump((new ReflectionFunction(' | ||
- | // 2 | + | // 1 |
</ | </ | ||
From the example above, it becomes more obvious why the initializer < | From the example above, it becomes more obvious why the initializer < | ||
calling the function. | calling the function. | ||
- | |||
- | //Side note:// It's been suggested that expressions that can be evaluated constantly continue to do so. This would mean that some expressions in < | ||
===== Other semantics ===== | ===== Other semantics ===== |
rfc/arbitrary_static_variable_initializers.txt · Last modified: 2023/05/24 18:29 by ilutov