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/16 11:07] – Fix reflection example ilutov | rfc:arbitrary_static_variable_initializers [2023/03/16 14:39] – Fix typos theodorejb | ||
---|---|---|---|
Line 26: | Line 26: | ||
</ | </ | ||
- | The right hand side of the assignment < | + | The right hand side of the assignment < |
that it can't call functions, use parameters, amongst many other things. This limitation is hard to understand from a | that it can't call functions, use parameters, amongst many other things. This limitation is hard to understand from a | ||
user perspective. This RFC suggests lifting this restriction by allowing the static variable initializer to contain | user perspective. This RFC suggests lifting this restriction by allowing the static variable initializer to contain | ||
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 (that are known at compile time) | ||
+ | * Class constants (that are known at compile time) | ||
===== Vote ===== | ===== Vote ===== |
rfc/arbitrary_static_variable_initializers.txt · Last modified: 2023/05/24 18:29 by ilutov