Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101698 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69346 invoked from network); 26 Jan 2018 18:16:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2018 18:16:33 -0000 Authentication-Results: pb1.pair.com header.from=cschneid@cschneid.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=cschneid@cschneid.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cschneid.com from 62.12.172.119 cause and error) X-PHP-List-Original-Sender: cschneid@cschneid.com X-Host-Fingerprint: 62.12.172.119 darkcity.gna.ch Received: from [62.12.172.119] ([62.12.172.119:57432] helo=mail.gna.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/35-35287-D707B6A5 for ; Fri, 26 Jan 2018 13:16:31 -0500 Received: from [10.183.1.94] (unknown [217.192.174.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 1217135C12 for ; Fri, 26 Jan 2018 19:16:27 +0100 (CET) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Message-ID: <517F0F7B-CD01-4F35-9021-8336B7BA06E1@cschneid.com> Date: Fri, 26 Jan 2018 19:16:26 +0100 To: PHP Internals X-Mailer: Apple Mail (2.3445.5.20) Subject: Shorthand proposal for associative arrays From: cschneid@cschneid.com (Christian Schneider) Hi there, I have a proposal for a shorthand notation of associative arrays = borrowed from another language: :$foo would be equivalent to 'foo' =3D> $foo and would work with array, list or [] Motivation behind it, maybe someone else finds more good uses: 1) Emulating named parameters with associative arrays like html::img([ 'src' =3D> $src, 'alt' =3D> $alt ]); could be written as html::img([ :$src, :$alt ]); which encourages consistent naming of variables and parameters 2) Simplifying list destructuring with non-integer keys, example taking = from = http://php.net/manual/en/migration71.new-features.php#migration71.new-feat= ures.support-for-keys-in-list foreach ($data as ["id" =3D> $id, "name" =3D> $name]) { becomes foreach ($data as [ :$id, :$name ]) { which reduces redundancy. I implemented a minimal patch (2 lines are added to the parser) to = implement this which you can find at https://cschneid.com/php/php7_2/assoc_array_shorthand.patch What do you think, is this worth an RFC? I hope I didn't miss an = existing one :-) Regards, - Chris