Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:26464 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42488 invoked by uid 1010); 10 Nov 2006 12:41:02 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 42473 invoked from network); 10 Nov 2006 12:41:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2006 12:41:02 -0000 Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 213.152.38.186 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 213.152.38.186 freshmint.phcomp.co.uk Linux 2.5 (sometimes 2.4) (4) Received: from [213.152.38.186] ([213.152.38.186:61384] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/90-37447-C5374554 for ; Fri, 10 Nov 2006 07:41:01 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.63) (envelope-from ) id 1GiVMz-0001jQ-Bq; Fri, 10 Nov 2006 12:20:29 +0000 Date: Fri, 10 Nov 2006 12:20:29 +0000 To: Sebastian Bergmann Cc: internals@lists.php.net Message-ID: <20061110122029.GY6982@mint.phcomp.co.uk> References: <7c3b2950611091321y649266abs4f3a5bac7187e889@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] Feature request From: addw@phcomp.co.uk (Alain Williams) On Fri, Nov 10, 2006 at 12:55:45PM +0100, Sebastian Bergmann wrote: > Dmitry Shirokov wrote: > > > function foo() > > { > > return array(1,2,3,4,5,6); > > } > > > > echo foo()[4]; // <---- it that > > // or may be (foo())[4] ? > > > > > > // instead of > > $var = foo(); > > echo $var[4]; > > ?> > > Although I am not a huge fan of method chaining in general (see [1]), > I am happy to have it in PHP as it faciliates fluent interfaces [2]. > > I makes IMHO perfect sense to also allow a similar syntax for arrays. > But the implementation should be closed (in the mathematical sense), so > that $o->m()[0]->n() also works, for instance, when m() returns an > array that has an object with method n() at index 0. Also constants, eg: $numDays = array(31,28,31,30,31,30,31,31,30,31,30,31)[$month]; Any expression has type & value and you should be able to apply any operator that is appropriate to that type regardless of where the value comes from, be that: variable, literal, function, expression. So all of the following should work: $monthLength = array(31,28,31,30,31,30,31,31,30,31,30,31); $numDays = $monthLength[$month]; $numDays = array(31,28,31,30,31,30,31,31,30,31,30,31)[$month]; $numDays = array_merge(array(31,28,31,30,31,30), array(31,31,30,31,30,31))[$month]; $numDays = $months->lengths[$month]; Only the first one currently does. Expressions should also work, thus: $f = ('abcd' . 'efgh'){5}; I looked up the precedence table ( http://www.php.net/manual/en/language.operators.php ) to see if I would need parenthesis in $months->lengths[$month] (perhaps ($months->lengths)[$month]) but -> is not listed as an operator in the precedence table. Please can someone put it in! > -- > [1] http://en.wikipedia.org/wiki/Law_of_Demeter > [2] http://www.martinfowler.com/bliki/FluentInterface.html -- Alain Williams Parliament Hill Computers Ltd. Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ #include