Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48668 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58801 invoked from network); 7 Jun 2010 08:07:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jun 2010 08:07:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=newrevolutions@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=newrevolutions@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: newrevolutions@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:41264] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 79/E0-51673-3B8AC0C4 for ; Mon, 07 Jun 2010 04:07:16 -0400 Received: by vws15 with SMTP id 15so4948510vws.29 for ; Mon, 07 Jun 2010 01:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=sjT10gx02EEIZhK7aVxj5I3/kXNf2jegvWx7MYb4D5E=; b=p8lkGpoD4lBiffF3b15NiHzUm6vVuZLg94/YVp48plDgyWbRxdzTrKG4sWBq9VIucf EncZwesFnUIPYCjGJeFqnIDWk1i1raqbhjvphfq5WiWrFu2EBQ1olv0QUWsqOoyhAWH7 R1rooWgkBLPkvhsGoVeKW6vvL9KWEXzSBBB4c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=VJW/NBF6ty/C9/nIBurIl+CbILETkHmiU+X2f6pmeEnwW8SCBQo+NkTi7KzWA7UYI9 oU+kIAU9fefu5mn3Ko1WhlCuWVSzi8qiTW+iesDCct8QP+V8fn099LE3rUeunklNq9HZ pHcOyeIZ0UyH+II0NM59wHteRWd1xRaeTWGao= MIME-Version: 1.0 Received: by 10.224.126.203 with SMTP id d11mr8461473qas.17.1275898033122; Mon, 07 Jun 2010 01:07:13 -0700 (PDT) Received: by 10.220.94.208 with HTTP; Mon, 7 Jun 2010 01:07:12 -0700 (PDT) In-Reply-To: References: <4C08A8B6.7080905@easyflirt.com> <4C08B717.9020304@easyflirt.com> Date: Mon, 7 Jun 2010 16:07:12 +0800 Message-ID: To: "mathieu.suen" Cc: RQuadling@googlemail.com, Richard Quadling , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Suggestion: echo function(var)[0]; From: newrevolutions@gmail.com (Harrison Yuan) Sorry for the ambiguity in my original message, and thanks to Tig for PM-ing me about that. To clarify, I support the syntax for: > echo function(var)[0]; and I believe this syntax: > $tmp =3D getimagesize('./path/to/image'); > echo $tmp[1]; to be awkward and inconvenient. Furthermore, it feels like an unrefined edge in the PHP syntax because in this case $tmp is a completely throwaway variable. While coding I had always wished PHP could have "echo function(var)[0]" and would like to help make this possible. Are there any good reasons currently why the RFCs for this aren't getting accepted? - Harrison On Sat, Jun 5, 2010 at 6:47 PM, Harrison Yuan wr= ote: > > I don't understand what is holding PHP back from having this syntax. > > Tig said: > =A0$tmp =3D getimagesize('./path/to/image'); > =A0echo $tmp[1]; > ?> > > The need to assign the trivial variable $tmp first is completely arbitrar= y. Is it not a design goal somewhere that languages should allow the greate= st degree of literal expression possible, consistent with existing syntax &= semantics rules? > > I am new here but would be interested in helping with a patch (+ hopefull= y another RFC) for this. What exactly are the specific arguments against ar= ray dereferencing? > > - Harrison > > On Fri, Jun 4, 2010 at 4:19 PM, mathieu.suen = wrote: >> >> On 06/04/2010 10:00 AM, Richard Quadling wrote: >>> >>> On 4 June 2010 08:18, mathieu.suen =A0wrote= : >>> >>>> >>>> Hi >>>> >>>> Why not something more generic. >>>> Someone could think of a ValueNode. >>>> >>>> Then it could be use for object, array, any primitive type ... >>>> >>>> I will take the ValueNode as a non terminal grammar node. >>>> So first we could do that: >>>> >>>> ValueNode->method(); >>>> ValueNode::sMethod(); >>>> ValueNode[]; >>>> foo(ValueNode); >>>> echo ValueNode; >>>> $e =3D ValueNode; >>>> ... >>>> >>>> And a ValueNode could be define as: >>>> >>>> ValueNode : >>>> >>>> =A0 =A0 =A0NewStatement >>>> =A0 =A0| FunctionCall >>>> =A0 =A0| PrimitiveValue >>>> =A0 =A0| '(' ValueNode ')' >>>> =A0 =A0| ...; >>>> >>>> This would allow all this syntax: >>>> >>>> (new A())->foo(); >>>> foo(new A()); >>>> foo->bar()[1]; >>>> foo()[5]; >>>> >>>> and many others. >>>> >>>> >>>> On 06/04/2010 03:19 AM, Kalle Sommer Nielsen wrote: >>>> >>>>> >>>>> Hi Tig >>>>> >>>>> 2010/6/4 Tig: >>>>> >>>>> >>>>>> >>>>>> Would be at all possible to implement this kind of shortcut? >>>>>> >>>>>> >>>>> >>>>> Its called array-dereferencing and it was proposed countless times, >>>>> including by myself. There is an RFC for this[1] and it was planned o= n >>>>> the old PHP6 todo at the PDT[2]. >>>>> >>>>> [1] http://wiki.php.net/rfc/functionarraydereferencing >>>>> [2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13) >>>>> >>>>> >>>>> >>>> >>>> --Mathieu Suen >>>> >>>> >>>> >>>> >>>> >>> >>> Not an expert in this area, but does this mechanism limit you to using >>> single dimensional arrays? >>> >>> >> >> Of course not as soon as you add array access to a ValueNode >> >> ValueNode >> >> =A0 =A0.. >> =A0 =A0| ArrayAccess >> =A0 =A0...; >> >> This is very simple and it can refactor greatly the parser. >> >> -- Mathieu Suen >> >> >> >