Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105187 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65437 invoked from network); 10 Apr 2019 01:32:35 -0000 Received: from unknown (HELO mail-oi1-f196.google.com) (209.85.167.196) by pb1.pair.com with SMTP; 10 Apr 2019 01:32:35 -0000 Received: by mail-oi1-f196.google.com with SMTP id w139so28677oie.9 for ; Tue, 09 Apr 2019 15:29:34 -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; bh=Lq+KGIdEhn9483RU//5hjDkpnIzOOGTjVh1fxvQ1M8A=; b=nNDJfGNV4y51QE2toChYim4hOTatKUv9XRWqGfezjcD0SOvdygBzVPyvwG/v6tW7Pz pRJJOlu5FsLUjJT25k6msHOk4lPkzO3w01EB9VpI0HXu/9N9VPrWT2u8giBXgZ/PC1kL Rz41+t8Qkok+F0ubmhGwJCGaBHCWVXmilrzY6AGc+8/Dvzuy8IOUF6d3yf3tvnbaTI1D b680qVlv8l8VZUIqtQquozdDtk/DnEdijcZpid6OWibwP2MfAwodrxv3mPfNxQcrOQ+4 c5QGKwPm7ZOTAqyjv7ObyFSW/YqgLfUkWEidviHGvuO23bGmq9NtLUbP8xliBaU4/2iJ ASTg== 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; bh=Lq+KGIdEhn9483RU//5hjDkpnIzOOGTjVh1fxvQ1M8A=; b=uglbjdHOxREQI3qN16gViOyYzXbfcsfm+DWpkdixEy+PP2GLjrt+B70wROYgDQMmSr ++l1tmvEnvjFP2q2KeKPbJ1JSi1oo4IdQObkx3n7esUiN4iLqm7p1ch/Dt5HpcbbbhPo PN1YlW9EpyLAIdfhn0qUCzbrlxYJ0NKTccJiee6lmhnqkGKWpMYy3IyPfXf6dzN8UA+u qfKCqd5Ivs8g6Hnv7HcdOdB6iM1KzMhi0A6WLSlnB3tqd8EV9yWIc5Q6lWwj2ddgWazG FvCk9jlIdyw/ud5hOiDZlu+XRirMcBOsNOcNBcKp7GQCiXvBCSWoLte+aMiCL9XQEW/t gj0A== X-Gm-Message-State: APjAAAVoZQFb6F2DVFRz8t7JlShA+U8MsrptDteFfiljTgAxhRr5/6h6 iW9NJasgcTsCM6FceIQM8Ir0k837HT/UHQEZGhUes/Od X-Google-Smtp-Source: APXvYqwuUqJdptDWxf0SUWRNyOXnDr0JfSfizy39wrleFn7vGs1/SVHMgbNaYfmJLZ2DQr4nysMKiWq/yM5zQyzobCc= X-Received: by 2002:a05:6808:650:: with SMTP id z16mr522501oih.100.1554848974244; Tue, 09 Apr 2019 15:29:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 10 Apr 2019 05:29:32 +0700 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000ca0e990586207c01" Subject: Re: [PHP-DEV] Re: [RFC] Arrow functions / short closures From: webdevxp.com@gmail.com (Kosit Supanyo) --000000000000ca0e990586207c01 Content-Type: text/plain; charset="UTF-8" Hi internals, This is my first write to this list but I've been followed your discussions quite a while ago. For a brief introduction, my name is Kosit, I'm a programmer from Thailand and I've been using PHP since version 3 (for a short period before moving to PHP4). I'm a fan of `fn` syntax and OK to go with it but I would like to propose some extended syntax & behavior about binding. What if we can omit the `use` keyword at all and use only second parentheses for variable & reference binding and make the presence of second parentheses turn off implicit variable binding. $a = 0; $f1 = fn(): int => $a; $b = 0; $f2 = fn(): int () => $b; equivalent to $a = 0; $f1 = function () use ($a) { return $a; }; $b = 0; $f2 = function () { return $b; }; And what if we can omit parentheses at all if fn has no parameters. $f = fn => $this->doSomethingWithAB($a, $b); $multiStmtBody = fn { // ... }; When people want to import references (and addtional variables) they have to do it explicitly like before but without `use` keyword. $f = fn($y): array (&$arr, $x) => $this->doSomethingWithArrAndXY($arr, $x, $y); equivalent to $f = function ($y): array use (&$arr, $x) { return $this->doSomethingWithArrAndXY($arr, $x, $y); }; Second parens without `use` keyword may be ugly but can be seen as an abbreviation of old closure syntax. This can eliminate possible problems of reference binding (switching) syntax described in the RFC that may cause undesired behavior and performance problem because `use (&)` will make all variables by-reference bound. Summary: 1. No `use` keyword for binding. 2. The presence of second parentheses will turn off implicit binding. 3. Can omit parentheses if fn has no parameters. I apologize in advance for my bad English but I hope my idea can be taken into consideration or at least can be transformed into another useful idea. Regards, Kosit On Mon, Apr 8, 2019 at 9:07 PM Nikita Popov wrote: > > On Wed, Mar 13, 2019 at 4:56 PM Nikita Popov wrote: > > > Hi internals, > > > > Motivated by the recent list comprehensions RFC, I think it's time we took > > another look at short closures: > > > > https://wiki.php.net/rfc/arrow_functions_v2 > > > > This is based on a previous (withdrawn) proposal by Levi & Bob. It uses > > the syntax > > > > fn($x) => $x * $multiplier > > > > and implicit by-value variable binding. This example is roughly equivalent > > to: > > > > function($x) use($multiplier) { return $x * $multiplier; } > > > > The RFC contains a detailed discussion of syntax choices and binding modes. > > > > Regards, > > Nikita > > > > Heads up: I plan to start voting on this RFC tomorrow if nothing new comes > up. > > Most of the discussion was (as expected) about the choice of syntax. > Ultimately I think there are many reasonable choices we can make here, but > we should stick to a specific proposal for the purposes of the RFC vote. > None of the given arguments convinced me that some other syntax is > *strictly* better than the proposed fn($x, $y) => $x*$y -- it's more a > matter of some choices being slightly better in one case and slightly worse > in another. My personal runner-up would be \($x, $y) => $x*$y, but I > suspect that there are some people who are more strongly biased against > "sigil salad" than I am... > > Nikita --000000000000ca0e990586207c01--