Re: [RFC] [VOTE] Constant scalar expressions
| From: | Yasuo Ohgaki | Date: | Fri, 22 Nov 2013 01:09:48 +0000 |
| Subject: | Re: [RFC] [VOTE] Constant scalar expressions | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70271@lists.php.net to get a copy of this message | ||
Hi all,
On Thu, Nov 21, 2013 at 6:11 AM, Bob Weinand <bobwei9@hotmail.com> wrote:
> That'd just be outside of this RFC's scope:
>
> const ABC = [1, 2];
>
> is currently not allowed. Also you can't write ABC[0]. That'd be a whole
> other RFC to add array support for constants.
>
I understand it requires new codes(and flag) to make a constant
array/object.
> So we could enable it for (static) properties, but why should we?
>
> Additions of arrays would be the only valid operation, but can you imagine
> _any_ use case where we'd need that when the only dynamic operands (
> constants) can't be arrays?
>
I just thought constant array/object is useful for application settings, etc
that should not be changed.
Anyway, constant variables are useful for VM/op code optimization.
include('foo.php'); // const a = 123;
const b = a;
is allowed currently. We may restrict this behavior only to the same file,
so that VM/op code optimization can be done.
Currently, no expression is allowed with 'const'. Defining 'const' using
another constant with the same value is useless. It's a bad coding practice
in many case, I suppose.
I understand use cases of scalar expressions with constants, but I'm
concerned
loosing door for further optimizations. (e.g. $x = $x + 123 is faster than
$x = $x + a,
where a is 123 in constant var hash)
We may be better to restrict expressions with constants only to the same
file
even if we loose some benefits/flexibility in user code.
Is this discussed?
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net