Re: [RFC] Constant Scalar Expressions
| From: | Bob Weinand | Date: | Wed, 14 Aug 2013 14:23:41 +0000 |
| Subject: | Re: [RFC] Constant Scalar Expressions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-68518@lists.php.net to get a copy of this message | ||
Am 13.08.2013 um 14:13 schrieb "Anthony Ferrara" <ircmaxell@gmail.com>:
> Hello all,
>
> I'd like to propose a new RFC for 5.NEXT:
>
> https://wiki.php.net/rfc/const_scalar_expressions
>
> This allows for defining constant expressions which are resolved at compile
> time.
>
> for example:
>
> const FOO = 1 + 1;
> static $bar = 1 << 2;
> function foo($a = 1 | 2) {}
> class foo {
> public $bar = 1 << 2;
> }
>
> Thoughts?
>
> Anthony
It really would be nice to use constants in these constant expressions.
I think this would be particulary useful when using bitwise operators. Example:
const FLAG_A = 1;
const FLAG_B = 2;
const FLAG_C = 4;
With this proposal we would write:
function func ($arg = 1 | 2 | 4) # we now need to lookup first which constants have values 1, 2 and
4
But it would be much more understandable if we were able to write:
function func ($arg = FLAG_A | FLAG_B | FLAG_C)
Bob Weinand