Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111994 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14266 invoked from network); 3 Oct 2020 22:56:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Oct 2020 22:56:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 73CCE1804AA for ; Sat, 3 Oct 2020 15:09:07 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.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 15:09:03 -0700 (PDT) Received: by mail-io1-f42.google.com with SMTP id d197so5467147iof.0 for ; Sat, 03 Oct 2020 15:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=byp0EYMcMfBeHL94wMmq+CsxETT4TtWSsExNUgJH1P0=; b=YNkhcXKHE7a4K3C9D8jExR+5KXHpMyW0Q593w9lc1pWzZEXizTGM5bYdMI4bQTKyYC ehoeTOkhTc6ya6nQnhL19OonRLrqfhKUq7gCbCFciMozJUACJevV1SM3D/bddMVlZWJM cGACDcwylU43Khx7iHXk8XHGzeSPQVzgYRjrittcmxpeemUBGTSu5tx/emz14cjZj9mg M/47RULGEyDJ0CZVyxXSNL/Mn5bEsu2c9wmHdKKWVGLzita2OkHTF4uYTrCWLNqgJq6V AJE+VsyXI9nE0/pFQJrdMkS+HOeqgBjl05s49VAe5Bdf8KeTObAN+NLMKwY9sBM7FvCt o0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=byp0EYMcMfBeHL94wMmq+CsxETT4TtWSsExNUgJH1P0=; b=ZHHgRjrynNcqv6kc1KbTVgabQmh/ShNp8NmDoy/B4qzYOiKqz1ZM0gZOogsn6PX0fN 9WOWPOr+/wr3kOohH+W798F3OFxOIAYph86y51fUvIcu6sGzq4rfIoiyAba8hhHQdAK5 s7Bk+2E6zWsDxvr3A18YAYddAL+bS7WAgFPEWeG5VvpdrClF/J7pgsBuJ4TQcMjeGf7x JzWS3+FiCqKKC6Rg7CkjfWm912a2NczHkh6HoKvrw/obFq5XN4LGjTn60sBXe02TViUn F521qpxjYFD/0+2zMx/M0UaIBmpj1V8iaTiTYXy8TvoS0yB2VJqG4NSae5XxJDEwg/gV i36w== X-Gm-Message-State: AOAM532IAfSvAXT8JY8dNSsNjotoCSxfceslSaV5dyNiqgtHCiNwhD2K RklV89G4dIu/aL99NTpSxkpztktRHZAbejLJuXo= X-Google-Smtp-Source: ABdhPJxO154dfguRH3h59CWN6+2ubUDY4oxdcYDExqPbymHqLKJiE7fIbd2nMtSz/2TycVgbpn4TDPHH1gJbj+4XGKA= X-Received: by 2002:a02:a90f:: with SMTP id n15mr7471025jam.71.1601762940248; Sat, 03 Oct 2020 15:09:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 4 Oct 2020 00:08:53 +0200 Message-ID: To: Nuno Maduro Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000001166c705b0cb7fc0" Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: deleugyn@gmail.com (Deleu) --0000000000001166c705b0cb7fc0 Content-Type: text/plain; charset="UTF-8" Hi Nuno, thank you very much for kicking this off! The current state of short closure is very limited and I believe it was a stepping stone to get to this one. This time there's no drawback of making fn a reserved keyword since it already is. This change will lead to better consistency and it will fill in the expectation gap when using short closure in PHP. Best of luck for us on this RFC. On Sat, Oct 3, 2020, 23:09 Nuno Maduro wrote: > 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. > --0000000000001166c705b0cb7fc0--