Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111992 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9664 invoked from network); 3 Oct 2020 22:27:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Oct 2020 22:27:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BDEEC1804AA for ; Sat, 3 Oct 2020 14:39:47 -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-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (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:39:47 -0700 (PDT) Received: by mail-io1-f48.google.com with SMTP id d197so5426396iof.0 for ; Sat, 03 Oct 2020 14:39:47 -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=F66VGmmPjQZCUJUHqwQ6R/gqdpgtnSFcTHIdGH/Uhio=; b=E6k59ZeZkxvmjdHlGx8+5whpUgVAikBCzNUZAP/RigTWpa6UEoZUwHYQt0xhJ+WQBj qxRN4opuXCQ3gCC8Lg7vS2zGAx+inB9i37aCegIj/jvtirPemvMOVGIt3HXoGgWU/92L 5WipAI9oC1Wx4ak0jITb5jG/r6mrkJCRkBqyDu9PpmoK8yq9S3NwzNXLuMh0a4StyrVD 1oNtSTVn+Q65UXRnB/yMr/1p3fCw8z2+2lDGpHV3hV/xbDNEFKNTyOAUgp2a4VhwbDNz JoFyKRy8wLpyZxLo2+m+DBFGpoE1ktK/MDMrrXsvWBGAng07xFjGUP4U1/3Kwt2nrpT6 4EOw== 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=F66VGmmPjQZCUJUHqwQ6R/gqdpgtnSFcTHIdGH/Uhio=; b=bYipK3ZIFN8KMUZHN6mvg9kZCYfxhqLx/lV/ZxvBDUsVSmnNytWlSrxGtOiKxZSzQh eaxlJWCQ0RllmS0taxQJsvYykfkUfzLwfI7HmaP1pw7pLTS1iqp/18YBH1656I/9pica f0qeGM/s6ZMWbRq9dad8F3/LPQxWTXdNKtHU29eb6SvciZXgQVYV2G6VWXjwl27bJjmn CsykK2lXPpqYY0bXijzNcC0CLKIe0N7A5wx1r4Ygce8G4sBcBKAG3Jl9jZYwiAxfSu/q 4AB2gSmW5bjX6oMH8CBuPY3Q9JF7/lDt7A6wULxSixyMxE6aKCkiDp+Jd+KNVTnpsevd jErg== X-Gm-Message-State: AOAM533AYGuMpJBGc4/gCL5AL9QmqcdB8ev8Fkc+DQfLLO0Yf06JwItJ 3j6HdAgns3mTReHylGgWrZ1/uiSBW6diK3c4pic= X-Google-Smtp-Source: ABdhPJy6lQoi9FqjVFOZ5ZnKW4e+Bzb4J5Kup0amuJaqbv0O74iLEXax3aObjyTvebgHpHye+j1Sx/UTeK+7hZ2MIhQ= X-Received: by 2002:a02:c885:: with SMTP id m5mr431637jao.72.1601761183946; Sat, 03 Oct 2020 14:39:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 3 Oct 2020 23:39:32 +0200 Message-ID: To: Nuno Maduro Cc: PHP Internals List Content-Type: multipart/alternative; boundary="00000000000062593505b0cb1629" Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: ocramius@gmail.com (Marco Pivetta) --00000000000062593505b0cb1629 Content-Type: text/plain; charset="UTF-8" Hey Nuno, On Sat, Oct 3, 2020 at 11:09 PM 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. > Overall, seems like unnecessary added syntax for something that already works just fine. Pros: * unclear Cons: * more scope leak * +1 way to do what we already do just fine * more lexer/ast complexity for downstream projects If you want to make an RFC about it, it really needs a compelling "pros" section, because there aren't any, so far :-\ Greets, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --00000000000062593505b0cb1629--