Re: [RFC] Constant Scalar Expressions
| From: | Johannes Schlüter | Date: | Thu, 15 Aug 2013 23:57:03 +0000 |
| Subject: | Re: [RFC] Constant Scalar Expressions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-68542@lists.php.net to get a copy of this message | ||
On Thu, 2013-08-15 at 16:42 -0700, Stas Malyshev wrote:
> Hi!
>
> > Though obv, in reality we wouldn't use runkit_constant_add(), it'd be a
> > new opcode which had the same effect. This is basically transparent to
> > opcode caches, allows the constant to actually change based on runtime
>
> If the class definition can actually change at runtime, I think it'd
> make it much harder for opcode caches since they can't any longer assume
> class definition can't change at any random place in the code.
>
> But this is not the most tricky part. The most tricky part is this:
>
>
> if(true) return;
> class Foo {
> const halfpie = M_PI/2;
> }
>
> Now what happens if this is implemented as an opcode? We can't run any
> opcodes past return statement, but Foo is expected to be defined here.
note that we have this functionality already:
$ php -r 'class A { const C = FOO; } define("FOO", 23); echo A::C;'
23
The first fetch will resolve that.
If we add "constant scalar expression" this has to work for class
constants, too. Else we add crazy new inconsistencies to the language.
johannes