Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101701 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76871 invoked from network); 26 Jan 2018 20:00:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2018 20:00:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.52 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.214.52 mail-it0-f52.google.com Received: from [209.85.214.52] ([209.85.214.52:33937] helo=mail-it0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/76-35287-4F88B6A5 for ; Fri, 26 Jan 2018 15:00:53 -0500 Received: by mail-it0-f52.google.com with SMTP id m11so25265340iti.1 for ; Fri, 26 Jan 2018 12:00:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ZixL0xh7/xeqGFs3LiXEZQasCPd7llfegBGlK6E8wwY=; b=IuLvnrCbPMpEloEis0RCv3X6XiM3/WrlE+EbB11xzi+i+XLveMB5xuJLb4MxxfcWiK 038p5JLeq1EhPFAj01DZoKVniyTzAC88UFa3jiM6Cc4pingA8O2Q2NNmGZujlRls47zU f9tl5MpBBcsc79SD+Q3KnnzVp4P/vPvL8uen1DagXT/8iIvvit7tDpPEDrIhBVkcfEPi l2P3blWlEYiXBANSGDaXWd2zlgyF6RVb8PKkjvDarbEzS5gpTlr7F4WeGhMiF3rYDPkE pDAMpMR1sdVCDcPeWuE1C+RfIAuUoEaWhwe76t1pbt7GMoIv5H05nrp5Z+dVoYWiUDtP M+wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ZixL0xh7/xeqGFs3LiXEZQasCPd7llfegBGlK6E8wwY=; b=Q40+w/UU8VlxpwgM99XnMeL9kIuISe3tWLV9ljE8ZGHgZxvn80VhEvZlCL0qM4ZgZ6 Bz7ovCc+S7V/UUUatOIQJxb3EG4c7JCMr5B3A/k58guqLlKgr6pxgv87KHwA9RZ+Z8Vs BD53oWzLqzBtd7FLzWeGIWQKdA1j9wtAgO4y055RLalin7RYCNIvke4wHfgElw9AhJbO vkn9PD6L0jzm1lflf5H7l7XhQmfeqZtVVMpU0+ChYvLhz8yLmx+Q/wdHeoPSbY1PZENt smp5eEcrZU7TJ4C8tRl6AvXe6di5vVnmNCaRSAQCYrOsiEq9XlncU4rmiXARdobbnYhB uoUA== X-Gm-Message-State: AKwxytcCHPEBUusO48WH8LhgWNeQN8lIqSNImNiihWOaX9wy5HzKt+yG 3l11DkVO5ssXfL0htNTkUNFid+Pe1VSgFgLXAU4= X-Google-Smtp-Source: AH8x2258s25C3xXgrG8vzQc/gpm8EbTx0jn799Ii/INa6RIufts7MQcJ8Kg1fjWKl2c2dcFEccjh2bq2sumg/jqLI8Y= X-Received: by 10.36.47.5 with SMTP id j5mr17414900itj.123.1516996849567; Fri, 26 Jan 2018 12:00:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.48.211 with HTTP; Fri, 26 Jan 2018 12:00:29 -0800 (PST) In-Reply-To: <517F0F7B-CD01-4F35-9021-8336B7BA06E1@cschneid.com> References: <517F0F7B-CD01-4F35-9021-8336B7BA06E1@cschneid.com> Date: Fri, 26 Jan 2018 18:00:29 -0200 Message-ID: To: Christian Schneider Cc: PHP Internals Content-Type: multipart/alternative; boundary="001a1143ce48580f180563b35a2e" Subject: Re: [PHP-DEV] Shorthand proposal for associative arrays From: david.proweb@gmail.com (David Rodrigues) --001a1143ce48580f180563b35a2e Content-Type: text/plain; charset="UTF-8" Maybe you should see the extract() method. It will receive strings as varargs and will create an associative array with the string name and the value, similar to your first example. html::img(extract('src', 'alt')); 2018-01-26 16:16 GMT-02:00 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' => $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' => $src, 'alt' => $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-features.support-for-keys-in-list > foreach ($data as ["id" => $id, "name" => $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 > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- David Rodrigues --001a1143ce48580f180563b35a2e--