Re: [PHP-DEV] Unexpected results from constant folding

This is only part of a thread. view whole thread
  98546
March 15, 2017 21:14 nikita.ppv@gmail.com (Nikita Popov)
On Wed, Mar 15, 2017 at 3:53 PM, Sara Golemon <pollita@php.net> wrote:

> On Wed, Mar 15, 2017 at 5:36 AM, Nikita Popov ppv@gmail.com> > wrote: > > Yes, this should behave as C. See also https://bugs.php.net/bug.php? > id=69676 > > for an existing bug report on the topic. > > > Given that bug is assigned to you, I'll just leave it in your hands then? > > > I think in 7.1 it might be even fairly simple so fix this: IIRC we now > store > > the defining CE on inherited constants, so we should know the scope to > > resolve against. > > > Even in 7.0 you could rewrite unresolved self:: references to the > current classname.Not as clean when it comes to producing error > messages, but certainly a quick and easy fix for the case where the > userspace code isn't broken. > > I had initially been thinking multi-pass, but there are some pretty > easy edge cases to fall into there...
Fixed in 7.1 by https://github.com/php/php-src/commit/2bba4a0d7f6d5e5712d60bc1cf2119622d837e55 .. I personally don't consider a PHP 7.0 backport worthwhile, as this is a long standing issue (from early PHP 5 days) and the fix will probably be hacky on 7.0. Note that CT resolving self:: doesn't quite cut it, because you also have to deal with parent::, which the compiler currently does not track. An alternative would be to force a full constant update on any parent CE, to ensure they will be evaluated in the correct order. Of course, this has other side effects, because it changes the point in time at which a certain constant is updated. Regards, Nikita
  98547
March 15, 2017 21:36 pollita@php.net (Sara Golemon)
On Wed, Mar 15, 2017 at 4:14 PM, Nikita Popov ppv@gmail.com> wrote:


> I personally don't consider a PHP 7.0 backport worthwhile, as this is a long > standing issue (from early PHP 5 days) and the fix will probably be hacky on > 7.0. > Probably not, but I like to think out loud. :)
> Note that CT resolving self:: doesn't quite cut it, because you also > have to deal with parent::, which the compiler currently does not track. > It doesn't track the specific ce (because it may not know the real
parent until runtime), but we have the extends node which gives us the parent's name and that could be rewritten in the same way as self.
> An alternative would be to force a full constant update on any parent CE, to > ensure they will be evaluated in the correct order. Of course, this has > other side effects, because it changes the point in time at which a certain > constant is updated. > Yeah, there's too many edge cases to go down that rabbit hole, and as
you say, it's a much older bug than 7.0 even. So best face forwards on this one. -Sara