Unexpected results from constant folding

From: Date: Wed, 15 Mar 2017 02:43:54 +0000
Subject: Unexpected results from constant folding
Groups: php.internals 
Request: Send a blank email to internals+get-98531@lists.php.net to get a copy of this message
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. -Sara

« previous php.internals (#98531) next »