Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75158 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 220 invoked from network); 1 Jul 2014 05:48:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2014 05:48:22 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.172 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.172 mail-vc0-f172.google.com Received: from [209.85.220.172] ([209.85.220.172:61920] helo=mail-vc0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/62-19251-5AB42B35 for ; Tue, 01 Jul 2014 01:48:22 -0400 Received: by mail-vc0-f172.google.com with SMTP id hy10so8609437vcb.3 for ; Mon, 30 Jun 2014 22:48:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=J9nETFBTHeTpW397nBO15ouvwNKXjjH0lA5NbOS4h4Q=; b=fGFAt4FL1YQDqQAW4xv5UNcJ/IHzl55B9Bd2P9EkT40HJE/jvKZTCjUVHYj/yGQEEE /aWaKECj/U+h2cHy9JKBN2I0jAMR4/+/q2+gBr0fBIGUSpEhOwgynTlKKJyrBNyuskGj l89kdIcmLBxG8EpdqNYTi8BfP4RsNAjqPcdfq87GkMdIxwzK+3yDZJRvjNxYKCJHT6F9 xOJk3ZvRi5b0PlBZNdFraZCy5Q/bWM94ofjfQHq1a16igKMq4Dlzt1SuNb5nLPw1NYrk AJrUF1f+2dkWzHrynElnLbgjbcuBL/Z53cFj6xeVYj7eGv7QO7C5hHJm7PMjP4i9M1B2 +ZLg== X-Gm-Message-State: ALoCoQmZILU0WFjPCjbHDKVRzl8FZwJqXqXVORUxdB+NntIJ4xAZ7wIDQT7VzuUQMS5lUt4D5u5U6IBJXcBCEHcLe0blvrT78qCNhpg75wttCII12R2Q5tYA5Ijpn3IJEbYePPqpxgL1 MIME-Version: 1.0 X-Received: by 10.58.228.74 with SMTP id sg10mr41095455vec.6.1404193699030; Mon, 30 Jun 2014 22:48:19 -0700 (PDT) Received: by 10.52.111.71 with HTTP; Mon, 30 Jun 2014 22:48:18 -0700 (PDT) In-Reply-To: References: Date: Tue, 1 Jul 2014 09:48:18 +0400 Message-ID: To: Andrea Faulds Cc: Bob Weinand , Xinchen Hui , David Soria Parra , Julien Pauli , PHP Internals Content-Type: multipart/alternative; boundary=047d7bd6a91ca0852404fd1b52a1 Subject: Re: [PHP-DEV] Wired constant expression syntax and bug From: dmitry@zend.com (Dmitry Stogov) --047d7bd6a91ca0852404fd1b52a1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. Look into the following scripts: =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' ?> =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 allowed in constants at run-time ?> =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 use them? ?> Where is the logic? Thanks. Dmitry. > > It is surprising that it wasn=E2=80=99t in the RFC though, I suspect that= was just > an oversight on Bob=E2=80=99s part. > -- > Andrea Faulds > http://ajf.me/ > > > > > --047d7bd6a91ca0852404fd1b52a1--