Re: Wired constant expression syntax and bug
| From: | Bob Weinand | Date: | Mon, 30 Jun 2014 21:29:07 +0000 |
| Subject: | Re: Wired constant expression syntax and bug | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75156@lists.php.net to get a copy of this message | ||
I'll add some tests later (Please remind me if I didn't add them until tomorrow evening).
Bob
Am 30.6.2014 um 21:32 schrieb Dmitry Stogov <dmitry@zend.com>:
> OK. I'll commit the patch.
>
> According to the wired syntax, note that your example code will make PHP at first construct an
> array and then destroy it.
>
> why not to write $var = DO ? "value1" : "value2";
>
> it must be more clear and efficient.
>
> In case you like to keep this new syntax in PHP-5.6 at least please cover it with tests.
> I'm not a big fun of it, but won't object if it can't make real harm.
>
> Thanks. Dmitry.
>
>
> On Mon, Jun 30, 2014 at 11:21 PM, Bob Weinand <bobwei9@hotmail.com> wrote:
> That syntax wasn't part of the RFC because it wasn't yet possible (existence of
> IS_CONSTANT_ARRAY at that time).
> Also the use case for that one is mainly:
>
> class Foo {
> public $var = ["value1", "value2"][DO];
> }
>
> And then just write
> const DO = 0; (or 1)
>
> I don't exactly know at which point that conflicts with opcache. Or if that really fixes
> the bug.
> The copying itself in your patch looks fine, but please take the responsibility for it and
> apply it yourself.
>
> Thanks,
> Bob
>
> Am 30.6.2014 um 21:06 schrieb Dmitry Stogov <dmitry@zend.com>:
> > Hi Bob,
> >
> > I'm wondered why you introduced this wired syntax in PHP-5.6.
> >
> > class FooBar {
> > const bar = ["bar" => 3]["bar"];
> > }
> >
> > It wasn't a part of RFC, it wasn't covered by tests, and it actually
> > doesn't make a lot of sense. May be it's better to remove it?
> >
> > Also I found a constant expression related bug, that leads to unpredictable
> > crashes from time to time. Previously we had IS_CONSTANT_ARRAY that was
> > handled in a special way. When you replaced it with IS_ARRAY, you missed
> > this handling, and I missed it as well when reviewed your patch. Now
> > IS_ARRAY constants might be incompletely copied from OPCache shared memory
> > and modified (incremented/decremented reference counter) directly in SHM.
> > Such modifications occur in simultaneously running processes and this
> > finally leads to crash on some race condition.
> >
> > It's possible to emulate the problem running the following script with
> > opcache.protect_memory=1
> >
> > <?php
> > function foo($query = NULL, array $exclude = array('q')) {}
> > foo();
> > ?>
> >
> > I propose a simple fix:
> > https://gist.github.com/dstogov/b73884e252b376957ebc
> > Please review and apply if agree.
> >
> > Thanks. Dmitry.