Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37148 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71431 invoked from network); 20 Apr 2008 05:12:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2008 05:12:22 -0000 Authentication-Results: pb1.pair.com header.from=mjlivelyjr@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=mjlivelyjr@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.46.29 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mjlivelyjr@gmail.com X-Host-Fingerprint: 74.125.46.29 yw-out-2324.google.com Received: from [74.125.46.29] ([74.125.46.29:15410] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/23-54185-3B0DA084 for ; Sun, 20 Apr 2008 01:12:21 -0400 Received: by yw-out-2324.google.com with SMTP id 5so702205ywb.83 for ; Sat, 19 Apr 2008 22:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=jGq0jR96s35wPx3w+Eu1gPlB3T1Jy+UY5yoAnZIDphQ=; b=qSiyBKNIRk7uTQX9oFVAQboclLlWwBjgDe6ua+sYUybB0LUCd7E3OJiEif8Ffag3V+tLPMsHReL5RZfNPBqTELh3ehWoZa1ZiWP811/upsIiwNbwCYbboXYH2NJGcESF4bep1l7AdwxAsmsJjnAz5ZkxW59X4C9xWg01i3Jj7As= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=f1AddURk8dl/XU6q9Pg7ko0IbFPDQ1IgHKp8YjKnvhthJNBiCdtSIMcphAjC2Aa6xfMkcDQJZedukWSysjbD4QZFssw6S2d2tYDfwxxMqvttLCqe2rQSeYDPptWkzH+PTbiJYNKfU/2lOf6uH/lqdm2E1B/xI0VcQbQQS+lOvPI= Received: by 10.151.15.13 with SMTP id s13mr1590551ybi.200.1208668335783; Sat, 19 Apr 2008 22:12:15 -0700 (PDT) Received: by 10.150.204.18 with HTTP; Sat, 19 Apr 2008 22:12:15 -0700 (PDT) Message-ID: <7495478f0804192212m17552ad0k59e61469a9aaaba8@mail.gmail.com> Date: Sat, 19 Apr 2008 22:12:15 -0700 To: "Kalle Sommer Nielsen" Cc: internals@lists.php.net In-Reply-To: <20080418104018.epguxp7v4844oowk@zesix.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5998_9682026.1208668335777" References: <20080418104018.epguxp7v4844oowk@zesix.com> Subject: Re: [PHP-DEV] Array access on function returns From: mjlivelyjr@gmail.com ("Mike Lively") ------=_Part_5998_9682026.1208668335777 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, Apr 18, 2008 at 10:40 AM, Kalle Sommer Nielsen wrote: > Hey Internals > > I've been wondering for quite some time why PHP doesn't allow you to > access > arrays when you assign it to a value like in Javascript: My opinion on features such as this is that they provide too much opportunity to do things in a far less than optimal way. Another feature that was brought up (allowing method calls directly on the constructor) has the same problem. I realize that this type of functionality seems appealing when you need to operate on only one index of an array or when you only want to make a single method call on a newly instantiated object. But it is going to do it at the cost of readability (imo) and in some cases reduce the speed or flexibility of the code. If you reference the 'index' of the return value of a function you in effect have lost access to all other indexes in the array. So, as soon as you need another index you are forced to either rewrite your code to not access the method directly as an array, or you have to make another full function call to pull in the value. The same holds true for chaining function calls onto constructors. On the other hand it would be fun trying to track down exactly what you should be expecting from: $var = new Class()->call1()->property[0]->call2()[1]->wheeeeeee(); > function ArrayTest(Array $range) > { > return($range); > } > > $range = Array(1337 => Array('Hello World')); > > echo ArrayTest($range)[1337}; > > > I would really like to see this introduced in PHP sometime (Perhaps as an > extra addition to 5.3's new and sleek features). > > This is very useful in a few areas and can save a few lines of code here > and there. > > unfortunately Im not a C Programmer myself else I've would have provided a > patch for this =/ > > > Cheers > > Kalle Sommer Nielsen > Zend Certified Engineer > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > ------=_Part_5998_9682026.1208668335777--