Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75927 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83113 invoked from network); 23 Jul 2014 08:29:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2014 08:29:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 108.166.43.91 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 108.166.43.91 smtp91.ord1c.emailsrvr.com Linux 2.6 Received: from [108.166.43.91] ([108.166.43.91:59088] helo=smtp91.ord1c.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/D0-21666-4627FC35 for ; Wed, 23 Jul 2014 04:29:25 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp12.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id C5A2180464; Wed, 23 Jul 2014 04:29:23 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp12.relay.ord1c.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 283FD80746; Wed, 23 Jul 2014 04:29:23 -0400 (EDT) X-Sender-Id: smalyshev@sugarcrm.com Received: from Stass-MacBook-Pro.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net [108.66.6.48]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.2.10); Wed, 23 Jul 2014 08:29:23 GMT Message-ID: <53CF7262.7020106@sugarcrm.com> Date: Wed, 23 Jul 2014 01:29:22 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Bob Weinand , Dmitry Stogov CC: Nikita Popov , Julien Pauli , PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Weird constant expression syntax and bug From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! >> > 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) >> >> > 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/