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.
The main difference to Anthony's RFC is (apart from a few operators more) that constants can be involved in these scalar operations:
<?php const a = 1; const b = a?2:100; // here the value of the constant "b" is dependent on the constant "a" ?>
Adding parser support for scalar expressions: operations on constants or constant values.
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 GREETING = "HELLO"; const BAZ = GREETING." WORLD!" ?>
<?php class Foo { const FOO = 1 + 1; const BAR = 1 << 1; const GREETING = "HELLO"; const BAZ = self::GREETING." WORLD!" } ?>
<?php class Foo { const BAZ = 10; } class Bar { public $foo = 1 + 1; public $bar = [ 1 + 1, 1 << 2, Foo::BAZ => "foo "."bar" ]; public $baseDir = __DIR__ . "/base"; } ?>
<?php const BAR = 1; function foo($a = 1 + 1, $b = 2 << 3, $c = BAR?10:100) { } ?>
<?php const BAR = 0x10; function foo() { static $a = 1 + 1; static $b = [1 << 2]; static $c = 0x01 | BAR; } ?>
None
PHP 5.NEXT
An implementation based off of current master is available: Implementation On GitHub (Diff On GitHub)
The patch is ready to be merged. (Opcache support is included, thanks to Dmitry)
The implementation of the scalar expressions is based on an AST. That AST implementation eventually could be used later as a general-purpose AST for compiler with a few tweaks.
The vote started the 20th November 2013 and ended the 27th November 2013.