rfc:fcc_in_const_expr
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:fcc_in_const_expr [2025/01/07 14:05] – timwolla | rfc:fcc_in_const_expr [2025/01/22 14:31] (current) – Set to under discussion edorian | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2025-01-07 | * Date: 2025-01-07 | ||
* Author: Tim Düsterhus (tim@tideways-gmbh.com), | * Author: Tim Düsterhus (tim@tideways-gmbh.com), | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 14: | Line 14: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes that it shall be legal to use the FCC syntax in constant expressions. | + | This RFC proposes that it shall be legal to use the FCC syntax in constant expressions. The semantics match the existing semantics of FCCs and of constant expressions. Aside from the obvious, this means: |
+ | |||
+ | * If a referenced class does not yet exist, the autoloader is triggered, as with < | ||
+ | * If a relative reference to a free-standing function is used in a namespaced context, the function will first be looked up within the namespace, falling back to the global namespace if it does not exist. | ||
==== Constraints ==== | ==== Constraints ==== | ||
Line 26: | Line 29: | ||
==== Scoping ==== | ==== Scoping ==== | ||
- | As with other constant-expressions, | + | As with other constant-expressions, |
- | All the features and examples of the proposal. This means that FCC in property default values //may// reference < | + | |
+ | ==== Examples ==== | ||
+ | |||
+ | < | ||
+ | <?php | ||
+ | |||
+ | # | ||
+ | class Attr { | ||
+ | public function __construct(public Closure $value) {} | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # | ||
+ | class C { | ||
+ | private static function myMethod(string $foo) { | ||
+ | return " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | foreach ((new ReflectionClass(C:: | ||
+ | $closure = $reflectionAttribute-> | ||
+ | var_dump($closure(' | ||
+ | } | ||
+ | |||
+ | // Prints: | ||
+ | // | ||
+ | // string(3) " | ||
+ | // string(3) " | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 52: | Line 83: | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
- | tbd | + | The current implementation uses a special AST structure to cache the resolved function for consistent behavior of the global function fallback. To correctly cache this AST structure, Opcache changes are required. The PR passes all tests both with and without JIT enabled. |
==== New Constants ==== | ==== New Constants ==== |
rfc/fcc_in_const_expr.1736258748.txt.gz · Last modified: 2025/01/07 14:05 by timwolla