You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, this is limited to the global scope.
This can be thought of as similar to C:
the static const can only be seen within the namespace block scope.
Differences from global constants:
- A name can only be declared once per namespace block.
- The name can only be used by the following statements in the namespace block.
- This can support any expression define() would accept
(function calls, $variable, properties, etc.).
- This is eagerly evaluated when the expression might be dynamic.
This is deliberate, and meant to make accidental infinite recursion
(and unexpected side effects of fetching a constant for the first time)
less likely.
This may throw in the future.
- The value from the first successful declaration is used and permanently stored.
Similarities to global constants:
- 'static const' rejects the same types
(references, objects, and reference cycles.)
- 'static const' cannot be modified once declared
The current implementation allows code such as this:
```php
static const LOCAL_X = "Local $x";
class Example {
const X = LOCAL_X;
}
```
Which is shorthand for:
```
if (!defined('UNIQUE_NAME_FOR_LOCAL_X')) {
define('UNIQUE_NAME_FOR_LOCAL_X', "Local $x");
}
class Example {
const X = \LOCAL_NAME_FOR_LOCAL_X;
}
```
Unfinished work:
- Work out what to do if the expression throws an exception/error.
(Fatal error? Leave as is?)
- Decide what this should do if the `define()` call fails.
(Fatal error? Throw a regular Error?)
- (Optional) opcache optimizations such as evaluating functions at compile time.
0 commit comments