Hi! >> <?php >> class Foo { >> const BAR = [0]; >> static $a = Foo::BAR; // constant array usage >> } >> var_dump(Foo::$a); // prints array >> var_dump(Foo::BAR); // emits fatal error >> ?> > > They can only be used in static scalar contexts. > > I wanted to introduce constants to be used and dereferenced also at run-time, > but that requires a RFC. > If anyone would allow me to introduce that still now (it'd be a relatively > simple patch), I'll happily do it. > The issue just was that I was a bit late to create a RFC (beta freeze etc...)
This example really makes little sense as described. So you can define Foo::BAR, but you can not actually use it? This doesn't sound good and would be a major WTF source. Why it requires an RFC to fix it? This is not the case for any constant in PHP now, as far as I know, so it should not be the case in 5.6 either. >> 3) The fact that constants are allowed in compile time and even stored, but >> can't be used confuses me as well as the error message "PHP Fatal error: >> Arrays are not allowed in constants at run-time". I agree, this is an extremely weird behavior - a user would assume if they successfully defined the constant they could use it. If there's a technical problem with having arrays there, it's better to not allow defining them then define them and set the trap for the user trying to use them. Notice that the constant could be defined in the library, and can change - so you have code like var_dump(Foo::BAR); that can suddenly stop working with fatal error because library defining Foo::BAR changed. This is not good. >> 5) Circular constant references crash (found by Nikita) >> >> <?php >> class A { >> const FOO = [self::BAR]; >> const BAR = [self::FOO]; >> } >> var_dump(A::FOO); // crashes because of infinity recursion >> ?> I think this is an instance of the same thing that makes one of the tests segfault. It is not a good thing to have release with such segfault, we need to find some fix to it ASAP. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php