Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111991 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6585 invoked from network); 3 Oct 2020 21:57:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Oct 2020 21:57:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DFBD21804C3 for ; Sat, 3 Oct 2020 14:09:52 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_KAM_HTML_FONT_INVALID autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 3 Oct 2020 14:09:52 -0700 (PDT) Received: by mail-oo1-f42.google.com with SMTP id w7so9835oow.7 for ; Sat, 03 Oct 2020 14:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=+jv3G1X68Uyin6Eadiu4MNBMDzDKJYQSXAuH6YcOGV0=; b=n8S5CqvTVDzL6NEvIoi88y8O1CV0zyzrSDbHnkBMiEQX5DQRcfBjWg3I+FiQyPoW1T /ID+aLPVRukRUo+P6wykFPUmyHbLQK0z0R0A7GCUoENJ9Kqk77KHTnH0TmfTS+vDh4D1 JIN1q07rANzGFpC1nRTjX3pNHgBvRw72YcXOrzTYNKDKSdrTkyM/MGkqSjKsAeEH9Pq4 e3eRU3pDDh8maIj5UsGXq3uUrM9Cb2Upzls0itdiJv4Ivw7yhBM7140+j8jwEbAA+7MB 8PRT9mqpzbrBeS011k4d8qzqtOSeXx+/5dpoELQfkamgHCNiXLL/rIO7U1uzRvqDko6a eMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=+jv3G1X68Uyin6Eadiu4MNBMDzDKJYQSXAuH6YcOGV0=; b=B6b06yGUf4Z40U07ij2sVw/3kniVHoyrh5c1nR8xKDT9fn+Dgw8ubgjbSFeQR6n+Qd y++KFgj0nEDGYDaImE9xGbDNwsFTOMJ8AlGuLPlCAbVxQ0Bhuri0NTOk/sczo5Aij3pZ p8PLuWaKZ8FSmlQZO8Dwwu4W79k2gwnmDiD1HwgzAoCqcSPvHnlsfzpmm+4tS9c1X7eV 3GR9i4sV9jTnIfMzpJDOmhJW60ALoRqNv0bpS4A3Iuh+5UOLgq/PnV0q73zNGiC1Fh/7 tUJKsYG9NbX+tl2DvA0b4IYWrfWatJ5ksra2WShaXirNm82d1fZSwLPyaaij/qTqQ6ql 6TyA== X-Gm-Message-State: AOAM530skyXNVf2FnJeYMPgbweW+wz2aDCYxsW2badd5s+N7cEP2y0lC 0CWAKKYl8HCTJyD8ifzehniPwq9UIZIzJ1uBXOAZll6ErnKa7g== X-Google-Smtp-Source: ABdhPJwVkHes/HkHj2Gy5PcvP5sebB9kTY27ZnuSBO+aw3Dk2akMwswrnhZt94VohJdmjNREr6fe2leCNHLmox9Mgz0= X-Received: by 2002:a4a:e781:: with SMTP id x1mr6834367oov.39.1601759389266; Sat, 03 Oct 2020 14:09:49 -0700 (PDT) MIME-Version: 1.0 Date: Sat, 3 Oct 2020 23:09:38 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000069b53105b0caabaa" Subject: RFC: Support for multi-line arrow functions From: enunomaduro@gmail.com (Nuno Maduro) --00000000000069b53105b0caabaa Content-Type: text/plain; charset="UTF-8" Hey internals, A few days ago I opened a pull request that adds support for multi-line arrow functions in PHP: https://github.com/php/php-src/pull/6246. As you may already know, PHP 7.4 has introduced one-liner arrow functions (aka short closures). Now, this pull request adds the possibility of those arrow functions to be multi-line. Just like in Javascript, or Hack. Let's see an example: ```php $users = [/** */]; $guestsIds = [/** */]; $repository = /** */; $guests = array_filter($users, fn ($user) => { $guest = $repository->findByUserId($user->id); return $guest !== null && in_array($guest->id, $guestsIds); }); ``` In short, the advantages are: ``` $values = array_filter($values, function ($value) use ($first, $second, $third) { // vs $values = array_filter($values, fn ($value) => { ``` - Multi-line arrow functions don't require the `use` keyword to be able to access data from the outer scope. - Also, in some cases, `fn (/** */) => {` is just shorter and simpler than `function (/** */) use (/** */) {`. This pull request has been very well received by the community on Github, and also on Twitter: https://twitter.com/enunomaduro/status/1311572174256340992. So, I am writing this email to get your feedback about having this feature in the core of PHP. Note that, if eventually, you think it is a good idea to create an RFC on this, I will need to get some RFC karma - my wiki account is nunomaduro. Regards, Nuno - https://twitter.com/enunomaduro. --00000000000069b53105b0caabaa--