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 [2023/03/15 16:58] – Fix out-dated comment on ReflectionFunction::getStaticVariables() ilutov | rfc:arbitrary_static_variable_initializers [2023/03/16 11:39] – Explain what is comp-time evaluable ilutov | ||
---|---|---|---|
Line 105: | Line 105: | ||
foo(2); | foo(2); | ||
var_dump((new ReflectionFunction(' | var_dump((new ReflectionFunction(' | ||
- | // 2 | + | // 1 |
</ | </ | ||
Line 195: | Line 195: | ||
// string(4) " | // string(4) " | ||
</ | </ | ||
+ | |||
+ | ==== What initializers are known at compile-time? | ||
+ | |||
+ | In the discussion the question arose whether static variables depending on other static variables are known at compile time. | ||
+ | |||
+ | <code php> | ||
+ | function foo() { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The answer is no. In this example it's clear that < | ||
+ | |||
+ | Here's a quick explanation of how this is implemented: | ||
+ | |||
+ | * Literals (strings, ints, bools, etc) | ||
+ | * Binary operations | ||
+ | * Binary comparisons | ||
+ | * Unary operations | ||
+ | * Coalesce operator | ||
+ | * Ternary operator | ||
+ | * Array access (< | ||
+ | * Array literals | ||
+ | * Magic constants (e.g. < | ||
+ | * Global constants | ||
+ | * Class constants | ||
===== Vote ===== | ===== Vote ===== |
rfc/arbitrary_static_variable_initializers.txt · Last modified: 2023/05/24 18:29 by ilutov