This RFC brings static scalar expressions to the parser. This allows places that only take static values (const declarations, property declarations, function arguments, etc) to also be able to take static expressions.
This can allow for writing far easier to understand code, by allowing for far more expressive code.
Adding parser support for compile-time resolved scalar expressions.
The following operations are currently supported by this proposal:
Also supported is grouping static operations: (1 + 2) + 3.
<?php const FOO = 1 + 1; const BAR = 1 << 1; const BAZ = "HELLO " . "WORLD!"; ?>
Note that constants are not supported within a declaration (since this happens at compile time). So const BIZ = FOO << BAR; would be a compile error.
<?php class Foo { const FOO = 1 + 1; const BAR = 1 << 1; const BAZ = "HELLO " . "WORLD!"; } ?>
<?php class Foo { public $foo = 1 + 1; public $bar = [ 1 + 1, 1 << 2, "foo " . "bar" ]; public $baseDir = __DIR__ . "/base"; } ?>
<?php function foo($a = 1 + 1, $b = 2 << 3) { } ?>
<?php function foo() { static $a = 1 + 1 static $b = [ 1 << 2 ]; } ?>
None
PHP 5.NEXT
None
None
None, as this is a pure compile-time construct, the generated op-array is the same as if there was no expression (it's purely static).
None
None
An implementation based off of current master is available: Implementation On GitHub (Diff On GitHub)
This patch is ready to be merged with tests.