Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112097 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77903 invoked from network); 21 Oct 2020 22:53:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Oct 2020 22:53:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0CFF31804DA for ; Wed, 21 Oct 2020 15:10:53 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2073.outbound.protection.outlook.com [40.92.23.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 21 Oct 2020 15:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UXRms6HOecQ+/UHLBIWg8MjOa0mcfvmz9q3svBXu8j0qL0viQPEc5dS5+osnRwve2J+WtwOJGP6B1VYqpUl/ZS35u3SUt3c24/h+sZTA6escIW7y9WNKwuMHnUNUGi3fhnZ1jZLBUjoh8l2MquKjNgbbnyKJPJ2Tfxk+54OWa7iEh5xP/zmQReMrjFZFSu+V7kRo/gVPsdTJsyoD96GhwDRyjCkdH+h6V31dYLKmI2mLvTB3cgmVvdPTaMQz3XjzSWbaMIf//ZzsMuNHOVO7cMSynL9HuuHJSKgNqqV2QrQgCKCV4B3WjXLk/Fp4r5rD7qqgN5qXzEWsXfxfzP2RBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eRbhYUBx61kRVEsJnK9i0Q7HHz5MbM2weGuz0cGoSes=; b=nl+WJovLvZ2xl5tJGK77r0bv/2pWxnSTURG0HWNlw13gu3PJdp75fMOTGhyQxl4xPds4++2pEouqpkqiNsmQ/2wjruDcCdob8mZ1ACtkuQEWOrm2YG8ZXQNrYGxkRS2k89bCYsoCy1AD4HtQFqa4WdlIkm56CMu6ApDJWfeWkkhi/F+A3vtNgNptYYq/jQARHmnme2cW4jgiD9sfcptfVRdLKqbhMeHqyorqghUSCJqZgFL+OMobtQ31V4dTSq95IZn9WqxuT8c+a29g0KJy+anVXM+OP54CLsJEkYFFI3rReQgNg5WdcOI8kP/BkanUyGpjYm/U9uhf0C24UAT0NA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eRbhYUBx61kRVEsJnK9i0Q7HHz5MbM2weGuz0cGoSes=; b=u8RFoevq8/+zdEwH8XZTbwo8kbFCOFgKdX7qOEbQRhsrc2Kxtv5EZWa/vz5w5p+7NGoP/L8ea8Zg9+KzDW8lbtuTvz2cYiRES3FfRWQbyjI3pAOjy3TmQ40AJ4jquGa+feW+1p4zV6bE+cJsdRDyGu0H4H9XDlOQiVAm1krZFutrGTMyNaGrY6xEmqHoAKK3ly6qx1WJA0/I9Sixyxyu/guxtwN+fWpuvIVO7OyHKu+PPbeStZ40GBlOOLXGaz8uUqL54y5WaP7HmpN7G4Nnb4y7X8YcwvVvizPrYych5ZW1WRCuodOnTL1NcYwmZJP3j6Qv5s8pYINW07AY53H+WA== Received: from MW2NAM12FT031.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::43) by MW2NAM12HT022.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.7; Wed, 21 Oct 2020 22:10:50 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT031.mail.protection.outlook.com (2a01:111:e400:fc65::382) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.7 via Frontend Transport; Wed, 21 Oct 2020 22:10:50 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::d99c:15a8:f595:d00]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::d99c:15a8:f595:d00%7]) with mapi id 15.20.3477.028; Wed, 21 Oct 2020 22:10:49 +0000 To: Larry Garfield , php internals Thread-Topic: [PHP-DEV] [RFC] Short-function syntax Thread-Index: AQHWpw2jJVJO6zFF/EuqX2WQBoESFqmiikwAgAASRro= Date: Wed, 21 Oct 2020 22:10:49 +0000 Message-ID: References: ,<812317f5-dd87-497b-b483-bc3b7f3c2e7d@www.fastmail.com> In-Reply-To: <812317f5-dd87-497b-b483-bc3b7f3c2e7d@www.fastmail.com> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:F988B8F52BB88FD2DA2A6061ECFB946A2236DF921BD060BE66FAD4574592FD9C;UpperCasedChecksum:8333E9C3355DAD9C4DFA7FAE113CF778ED734673A676637982189182578EEA61;SizeAsReceived:6917;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [LfKNPJkggMzjiKM0y17MBnM8ud0rY7g8] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 80d3f6dc-af94-4e42-bd1d-08d8760e2ac3 x-ms-traffictypediagnostic: MW2NAM12HT022: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bii9pTuwzZzvduu1UBzcC9hhgnd/Cjs9QgNN0jsy47r60v2zugWgv8EuwOSgCAmgNl0GTwTzW5svHzxgI37Lk85G0vO/2fhDkMpIqrjG/Fq2C+aR4lEz69i23OzTlTwOnxGvd34EOtlPRHQdF01FprikAeLwGqsWBnmOZESr7AXX3INY1vwb2SMZVR9T9dBGHNHm49o74o+ptDMSAyOvJHyu7B7QvQFB8okofu0NwLg7GSujL0so4evxwaqJNZ/j x-ms-exchange-antispam-messagedata: cgB58/2FlS79lQglwXAFkGFCOZhPx0R6XvBRN/7zBNcEKvznLDYX9hZ/7YCc0lV6Uzq2+MTRNCAkNQ+7aoMQhIKa8w0rNcTXVv2jC0yPxzLH5b5dl9S9Y5RHm9t4FQrFhRoItJ3HQ6OcRuFSvYKrdQ== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: MW2NAM12FT031.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 80d3f6dc-af94-4e42-bd1d-08d8760e2ac3 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2020 22:10:49.1166 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT022 Subject: Re: [PHP-DEV] [RFC] Short-function syntax From: tysonandre775@hotmail.com (tyson andre) Hi Larry Garfield,=0A= =0A= > > A while back, Nikita mentioned that it should now be easy to offer an = =0A= > > abbreviated syntax for functions that are just a single expression.=A0 = I =0A= > > decided to take a crack at it and it turns out he was right.=A0 I thus = =0A= > > offer this RFC:=0A= > > =0A= > > https://wiki.php.net/rfc/short-functions=0A= > > =0A= > > Hopefully I made a decent enough case for it.=A0 It's entirely a =0A= > > convenience factor, but I think for many OOP cases (getter methods and = =0A= > > factored out operations) and functional cases (where functions should = =0A= > > generally be a single expression conceptually) it does make the code = =0A= > > nicer, more compact, and more readable.=0A= > > =0A= > > *dons flame retardant suit*=0A= > =0A= > There's been some discussion on the PR that I'm looping back here for com= pleteness, mainly about using "function" vs "fn" for short named functions.= =0A= > =0A= > I can see good arguments for either, and in the end don't care all that m= uch.=A0 My main concern was that `function` was easier to implement, but Sa= ra graciously offered an alternate patch that uses `fn` instead.=A0 I'll ma= ke a PR out of that sometime later today.=A0 If we feel it's highly bikeshe= dable I'm happy to make that a secondary vote, or if a clear consensus emer= ges either way before then we can go with whatever that is.=A0 =0A= >=0A= > I think I moderately prefer `function` for visual consistency, especially= inside a class, but it's not a hill I feel like being moderately injured o= n. :-)=0A= =0A= The feature overall looks convenient.=0A= =0A= I'd also be against `fn` for the consistency - as the RFC says, "Functions = are simpler than lambdas, as there is no need for closing over variables co= ntextually"=0A= =0A= The major difference between `fn` and `function() {}` is the fact that the = former automatically uses variables by value from the outer scope,=0A= and it'd be confusing to reuse that for methods and/or global functions tha= t don't use variables for the outer scope.=0A= (I don't know if the RFC mentioned this explicitly)=0A= (e.g. `$multiple =3D 3; fn named_multiply($x) =3D> $x * $multiple;` is what= a user may expect `fn` to mean)=0A= =0A= I guess that was mentioned in the PR discussion already, but mentioning thi= s on-list for others: https://github.com/php/php-src/pull/6221#issuecomment= -713605293=0A= =0A= - Unrelated to this RFC: If we were ever to have class methods and named gl= obal functions that did take variables from the outer scope by reference (l= ike in Python), that may cause complications in opcache (e.g. for anonymous= classes),=0A= and I don't really have a use case for that. But `fn` would make sense fo= r that type of feature.=0A= =0A= -- Tyson Andre=