Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87991 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57995 invoked from network); 1 Sep 2015 10:37:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2015 10:37:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=tpunt@hotmail.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tpunt@hotmail.co.uk; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.co.uk designates 157.55.1.142 as permitted sender) X-PHP-List-Original-Sender: tpunt@hotmail.co.uk X-Host-Fingerprint: 157.55.1.142 dub004-omc2s3.hotmail.com Received: from [157.55.1.142] ([157.55.1.142:63990] helo=DUB004-OMC2S3.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/45-27722-8EF75E55 for ; Tue, 01 Sep 2015 06:37:28 -0400 Received: from DUB129-W89 ([157.55.1.137]) by DUB004-OMC2S3.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 1 Sep 2015 03:37:24 -0700 X-TMN: [K8L/NDHwp+MkX2NZku2GWCYvxHeCJsN6] X-Originating-Email: [tpunt@hotmail.co.uk] Message-ID: To: Bob Weinand , PHP Internals Date: Tue, 1 Sep 2015 11:37:24 +0100 Importance: Normal In-Reply-To: References: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 01 Sep 2015 10:37:24.0959 (UTC) FILETIME=[30E05EF0:01D0E4A2] Subject: RE: [PHP-DEV] [RFC] [Discussion] Short Closures From: tpunt@hotmail.co.uk (Thomas Punt) Hi Bob=2C=0A= =0A= > I had this RFC in draft since some time=2C but delayed it due to all the = ongoing PHP 7 discussions. Also we have no master branch to merge features = in until 5.4 EOL. Thus I'm reviving this now.=0A= >=0A= > Time for the first RFC targeting PHP 7.1 (assuming PHP 8 isn't going to b= e the next version =3B-)):=0A= >=0A= > The short Closures RFC:=0A= > https://wiki.php.net/rfc/short_closures=0A= >=0A= > Hoping for constructive feedback=2C=0A= > Bob=0A= =0A= Whilst I'd like to see a more expressive syntax for closures (and many othe= r=0A= things) in PHP=2C I'm personally -1 on your proposal. The feature feels too= =0A= inconsistent with the syntax and semantics of current PHP constructs for th= e=0A= following reasons:=0A= 1) The automatic binding of variables from the outer scope to the inner sco= pe.=0A= 2) The optional use of parentheses for parameter definitions=2C but only wh= en a=0A= single argument is used.=0A= 3) The optional use of braces for the function body=2C but only when a sing= le=0A= expression is used.=0A= 4) The automatic returning of the expression=2C but only when it is alone= =2C and=0A= only if the braces are omitted.=0A= =0A= These four differences create further special cases for people to learn and= =0A= have no precedence in the language at all. They seem more like Rubyisms tha= n=0A= PHPisms.=0A= =0A= Whilst we're on the topic of a terser syntax for closures though=2C Elixir = has an=0A= even shorter syntax:=0A= &(&1 + &2)=0A= =0A= The &() denotes an closure definition=3B the &N is used to create placehold= ers=2C=0A= where N corresponds to the argument number. The ampersand obviously cannot = be=0A= reused for this in PHP=2C but the dollar sign could:=0A= $func =3D $($1 + $2)=3B=0A= var_dump($func(3=2C 4))=3B // int(7)=0A= =0A= This syntax should only be used in trivial scenarios=2C though=2C and comes= with=0A= the disadvantage of no type information.=0A= =0A= Thanks=2C=0A= Tom=0A= =