Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101702 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78180 invoked from network); 26 Jan 2018 20:01:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2018 20:01:56 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.176 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-io0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:44801] helo=mail-io0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/B6-35287-3398B6A5 for ; Fri, 26 Jan 2018 15:01:56 -0500 Received: by mail-io0-f176.google.com with SMTP id z6so1603922iob.11 for ; Fri, 26 Jan 2018 12:01:55 -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=FC02lpiHyvwuJiphbxRihmMCSHvkYhbJTkzuTiYfpU0=; b=mbyB+1A3rOPTEZbdJz6uRWiFYwenixQJXVKxf2jmhCiDkyRjumAqEvIPWLx/6qXnOn ONqNFoAg4DC6VQIMYfyII+vTmf+wyaDpiuEuPjhvX3Ac8Mc4wDBYL2lh7vbO/sL9lIFh nu/1ZS+WKPdeH1BoXOP07B1SltI+EH7r8TrhxQ0mBB8PULLEfp9J8AXItsKdFoBY8BVd X+ShRaL/g5ecrNEfOTliur1djpwQ7JrInZEJB3jcFSfLDOugRTWK/UMMXj733ygMjX3e esO0mR0RgIUL3r0BQfn/ZjvauE7nuPyWgQnuFUdAugB0Bb42sE/k4TlAEcXRPdcPRiow Owrg== 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=FC02lpiHyvwuJiphbxRihmMCSHvkYhbJTkzuTiYfpU0=; b=l99FU5vkNRH6IzUEQs+BUofXNJkMhC35J1KklCZSlLEOYjYZgEbDoRy0G601MK3GjG 8TAob1wRd2h4DuTQTRNwmUbMdxqK0UFrBNyhVKwEtxT7RW/bCEAwUAsol7NW5vM5W+pD dGpK5mZBg16MIf8H7QNOhy2jtsZG2i/PWYW4Zn79lwRxjl87wfopSqBojtoyUVe0La9x vCMnEZK0i+172z+L+0/bQPM3FXazgnv4TN5cF0RADiHir0u3wDh7f9mP9XOZzpTeMWlD mXG6wtkmp6Nn08b2NO3IZWM1bATkfSDGEphQUyitPETmdfL+tyQG8ijz0BSddpsYe0CV t3bA== X-Gm-Message-State: AKwxytff34Qcyh0UXqQ1417hwG8RIbcmNXEtrqimVLI/X0m2uK4Ygn67 iHj010dR5klfz7zA1Rju7+zG3AWNxBsE39zRqqk= X-Google-Smtp-Source: AH8x2269mp72YCCgX9P+VNnb97ooNeHd4W+asCIeRlqLYA84mgq2bcfj0BC561+nODL+xcDPx0sMT4boqnv48LWugNM= X-Received: by 10.107.46.13 with SMTP id i13mr17909066ioo.161.1516996913093; Fri, 26 Jan 2018 12:01:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.48.211 with HTTP; Fri, 26 Jan 2018 12:01:32 -0800 (PST) In-Reply-To: References: <517F0F7B-CD01-4F35-9021-8336B7BA06E1@cschneid.com> Date: Fri, 26 Jan 2018 18:01:32 -0200 Message-ID: To: Christian Schneider Cc: PHP Internals Content-Type: multipart/alternative; boundary="001a1134e22c2168650563b35e92" Subject: Re: [PHP-DEV] Shorthand proposal for associative arrays From: david.proweb@gmail.com (David Rodrigues) --001a1134e22c2168650563b35e92 Content-Type: text/plain; charset="UTF-8" Sorry, the extract() function will receives an array as first argument. html::img(extract(['src', 'alt']); 2018-01-26 18:00 GMT-02:00 David Rodrigues : > 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#migrat >> ion71.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 > -- David Rodrigues --001a1134e22c2168650563b35e92--