On Wed, Mar 15, 2017 at 3:43 AM, Sara Golemon <poll...@php.net> wrote:
> This comes in thanks to my old friend Fred Emmott on the HHVM project: > https://3v4l.org/vUHq3 > > class Foo { > const A = 1 << 0; > const B = self::A | self::C; > const C = 1 << 1; > > } > > class Bar extends Foo { > const A = 1 << 2; > const C = 1 << 3; > } > > var_dump(decbin(Bar::B)); > // HHVM result: 11 > // PHP5 result: 1100 > // PHP7 result: 1001 > > HHVM's result is clearly correct as `self::` refers to the defining > class and so should bind to Foo's values for A and C. > PHP5's result is at least rationally viable, although it effectively > redefines `self::` to the semantics of `static::` just for this case. > PHP7's result is... well, I can imagine how it occurs, but it can't be > called correct by any measure. > > Opinions on the right thing to do here? > a) Leave it alone because it's been that way since 7.0 > b) Revert to php5 behavior > c) Match HHVM's behavior > > I vote C because that's the semantic meaning of self:: and we should > respect PHP's own language rules. > Barring that, I'd be okay with B as it's at least explainable without > too much mental gymnastics. > I straight up veto A. That's just cray-cray. > Yes, this should behave as C. See also https://bugs.php.net/bug.php?id=69676 for an existing bug report on the topic. 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. Nikita