Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27788 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51150 invoked by uid 1010); 5 Feb 2007 05:30:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51134 invoked from network); 5 Feb 2007 05:30:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2007 05:30:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 66.79.163.178 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 66.79.163.178 bluga.net Linux 2.5 (sometimes 2.4) (4) Received: from [66.79.163.178] ([66.79.163.178:38727] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/44-18726-301C6C54 for ; Mon, 05 Feb 2007 00:30:43 -0500 Received: from mail.bluga.net (mail.bluga.net [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id E04DF87868; Sun, 4 Feb 2007 21:20:30 -0800 (PST) Received: from [192.168.0.106] (CPE-24-169-242-149.neb.res.rr.com [24.169.242.149]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id 941B1874DB; Sun, 4 Feb 2007 21:20:30 -0800 (PST) Message-ID: <45C6BCFB.2090903@chiaraquartet.net> Date: Sun, 04 Feb 2007 23:13:31 -0600 User-Agent: Thunderbird 1.5.0.9 (X11/20070104) MIME-Version: 1.0 To: Andi Gutmans CC: internals@lists.php.net References: <011701c7482d$a39f6910$6500a8c0@zend.2k> In-Reply-To: <011701c7482d$a39f6910$6500a8c0@zend.2k> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: Syntactic improvement to array From: greg@chiaraquartet.net (Gregory Beaver) Andi Gutmans wrote: > Hi, > > I thought I may have brought this up a long time ago but couldn't find anything in the archives. > For a long time already I've been thinking about possibly adding a new syntax for array(...) which would be shorter. I'd suggest > [...]. While I am usually not in favor of having more than one way to do things, I think it'd look much more elegant especially (but > not only) for nested arrays. > > So what I'm thinking of is: > array(1, 2, 3) == [1, 2, 3] > array(1, 2, array("foo", "bar")) == [1, 2, ["foo", "bar"]] > array("key" => 1, "key2" => 2) == ["key" => 1, "key2" => 2] > > $arr = [1, 2, 3] > vs. > $arr = array(1, 2, 3) > > Well enough examples given :) > I think it's not worth doing unless there's overwhelming support as it's not desperately needed. But I'd be interested to hear > people's thoughts. It seems implementation shouldn't be an issue but I'd have to dive a bit deeper. future: now: For what it's worth, the examples above show why I'm a strong -1 on this idea. It introduces the possibility of weird misunderstandings that just don't exist now, and also introduces a new way to accidentally break your script that wasn't possible before. The only way I could see solving this would be: 1) [] != list() 2) use a[] as in $a = a[1, 2, 3] but then we might as well stick with array(). Either way, [] is overloaded in the new definition: 1) array access 2) ArrayAccess object offsetGet/offsetSet 3) incremental index ($a[] = 1;) 4) array creation [5) list()] Whereas now, it is only 3 possible meanings, all of which are consistent with a few quirks in the ArrayAccess one as of PHP 5.2. Greg