Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75160 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11170 invoked from network); 1 Jul 2014 08:26:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2014 08:26:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.175 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.128.175 mail-ve0-f175.google.com Received: from [209.85.128.175] ([209.85.128.175:35952] helo=mail-ve0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/90-03359-1D072B35 for ; Tue, 01 Jul 2014 04:26:57 -0400 Received: by mail-ve0-f175.google.com with SMTP id jx11so9205855veb.6 for ; Tue, 01 Jul 2014 01:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=NQsvm6kgC0AB5K2BHe1k6DcL1Sggji5mWpNUcGxjTNI=; b=KTWywouMajc/T5fVUvft6Z7Q0Z0JVCuOjwdMVxiSjbCzcCi5beyY0Sz7Xs48iynvYu DqA//GgAjM95v3wHG4X0NWEPjzizjnPnRJuO5o9qiFTI2qdr9KKGn5o1GE1sJhmJW0rL MR0GGxQQkhlV3xUwsqILzkuFaw9Uc3oTUpojdD5gyiZJO/ImST7dxPUxblDRbMzFMogk 16ZSrK8DCZmUHqHerbROssNoLwsEJCKZFoHk9uB1LI7WVYhVn8eGFL1uooWMk9zw/M2s svO2xTZxd+83eQuil3XPurvpbAYVUsX8du1OI8PdaAS8Z2ucijwPfeuHUcbUMkX0VML/ IC2A== X-Received: by 10.58.37.106 with SMTP id x10mr3078547vej.2.1404203214304; Tue, 01 Jul 2014 01:26:54 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.81.68 with HTTP; Tue, 1 Jul 2014 01:26:14 -0700 (PDT) In-Reply-To: References: Date: Tue, 1 Jul 2014 10:26:14 +0200 X-Google-Sender-Auth: 4jRK5BEOf1oDp_6noY4JsWDoKiU Message-ID: To: Nikita Popov Cc: Dmitry Stogov , Andrea Faulds , Bob Weinand , Xinchen Hui , David Soria Parra , PHP Internals , Ferenc Kovacs Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Wired constant expression syntax and bug From: jpauli@php.net (Julien Pauli) On Tue, Jul 1, 2014 at 9:12 AM, Nikita Popov wrote: > On Tue, Jul 1, 2014 at 7:48 AM, Dmitry Stogov wrote: >> >> On Tue, Jul 1, 2014 at 1:05 AM, Andrea Faulds wrote: >> >> > >> > On 30 Jun 2014, at 20:06, Dmitry Stogov wrote: >> > >> > > Hi Bob, >> > > >> > > I'm wondered why you introduced this wired syntax in PHP-5.6. >> > >> > Do you mean weird? >> > >> >> yes :) sorry >> >> >> > >> > > >> > > class FooBar { >> > > const bar =3D ["bar" =3D> 3]["bar"]; >> > > } >> > > >> > > It wasn't a part of RFC, it wasn't covered by tests, and it actually >> > > doesn't make a lot of sense. May be it's better to remove it? >> > >> > I disagree, it makes perfect sense: >> > >> > class FooBar { >> > const FOO =3D 3; >> > const BAR =3D [ >> > 3 =3D> =E2=80=98qux=E2=80=99, >> > 4 =3D> =E2=80=98bang=E2=80=99, >> > 7 =3D> =E2=80=98theta=E2=80=99, >> > 9 =3D> =E2=80=98epsilon=E2=80=99 >> > ][FOO]; >> > } >> > >> > ?: and ? only work when there are just two possibilities. >> > >> >> ?: may work with brackets, but I have to admit that it's less readable. >> >> class Foo { >> const X =3D 2; >> const Y =3D (Foo::X =3D=3D 0 ? 1 : >> (Foo::X =3D=3D 1 ? 2 : >> (Foo::X =3D=3D 2 ? 3 : >> (Foo::X =3D=3D 3 ? 4 : >> 5)))); >> } >> >> The situation is really inconsistent because we allow expressions on >> constant arrays but at the same time prohibit array usage. > > > As we support the [..., ...][...] syntax in normal PHP code as well, I th= ink > it's reasonable to allow it here as well. Of course it isn't very > practically useful, but there doesn't seem much point to explicitly > disallowing it here. > >> >> Look into the following scripts: >> >> >> > class Foo { >> const BAR =3D [ >> 3 =3D> =E2=80=98qux=E2=80=99, >> 4 =3D> =E2=80=98bang=E2=80=99, >> 7 =3D> =E2=80=98theta=E2=80=99, >> 9 =3D> =E2=80=98epsilon=E2=80=99 >> ][1]; >> } >> var_dump(Foo::BAR); // works - prints 'bang' >> ?> >> >> > class Foo { >> const BAR =3D [ >> 3 =3D> =E2=80=98qux=E2=80=99, >> 4 =3D> =E2=80=98bang=E2=80=99, >> 7 =3D> =E2=80=98theta=E2=80=99, >> 9 =3D> =E2=80=98epsilon=E2=80=99 >> ]; >> } >> var_dump(Foo::BAR); // doesn't work - Fatal error: Arrays are not allowe= d >> in constants at run-time >> ?> >> >> > class Foo { >> const BAR =3D [ >> 3 =3D> =E2=80=98qux=E2=80=99, >> 4 =3D> =E2=80=98bang=E2=80=99, >> 7 =3D> =E2=80=98theta=E2=80=99, >> 9 =3D> =E2=80=98epsilon=E2=80=99 >> ]; >> } >> // This works again! We may declare array class constants if we don't us= e >> them? >> ?> >> >> Where is the logic? > > > The reason here is probably that we cannot detect whether something will = be > an array or not until runtime constant updating. E.g. const BAR =3D FOO ?= 1 : > [1] or similar. However we might want to detect the case where an array i= s > the root of the AST, as that is invalid for sure and the most common case= . > > Another small issue with the constant expressions I noticed is that our > recursion detection doesn't properly work for constant ASTs. For example: > > class A { > const FOO =3D [self::BAR]; > const BAR =3D [self::FOO]; > } > var_dump(A::FOO); > > This will result in a stack overflow instead of a fatal error about > self-referencing constants. So what's the status ? We release RC2 this week. Final is not far, and as I can read, it's not sta= ble. So I suggest we use more RCs to try to make this stable (and I mean with OPCache activated). If we can't make it in reasonnable time, then the feature will have to be reverted. Please, note we won't have too many RCs as we are already late on our original timetable. Julien Pauli