Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103391 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48600 invoked from network); 26 Oct 2018 19:27:10 -0000 Received: from unknown (HELO wout1-smtp.messagingengine.com) (64.147.123.24) by pb1.pair.com with SMTP; 26 Oct 2018 19:27:10 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 98CFBC7F for ; Fri, 26 Oct 2018 11:42:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 26 Oct 2018 11:42:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=QLxtCW XwfDtUfig/Ybym1+O6HP9T0dfxXcmVtS/bMKk=; b=W2Pfhfrjq2/4Yf0d4pgz8I ce3El/6vpCc1GLkfZ2PiMIDDDf3HwLynlzMQvy7og+eD/zukrW7eNr+D37SC6tk2 TbtC7Z9JX1CJtJVgfMqnjCoEnDiLZUK5NkoJBtKBVQwWqRrszVam3EdQY0Nr6epg C6gktGhARPcXlNMO5X3wonKi33EiZO20jlAFWoKo03VVwQE3SSczFejKh/smexg/ vNBpa/YAK/xPLcFoT9R5E3awKe+IW5BLstru3IM6/5U4LMjw51+sL2TjlCxMJUB/ 7dimMZ6UAs39kcwLN3Wq5GlSwqdnYbcp1J7LIEpim5UBHjjGNNtHZuxt/5cwNnXg == X-ME-Sender: X-ME-Proxy: Received: from vulcan.localnet (216-80-30-152.s3222.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com [216.80.30.152]) by mail.messagingengine.com (Postfix) with ESMTPA id 98415E4074 for ; Fri, 26 Oct 2018 11:42:48 -0400 (EDT) To: internals@lists.php.net Date: Fri, 26 Oct 2018 10:42:47 -0500 Message-ID: <2370262.6EcsR2toYx@vulcan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart102715617.dvUWLDBhPU"; micalg="pgp-sha512"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV] Idea for better function callbacks (another syntactic sugar) From: larry@garfieldtech.com (Larry Garfield) --nextPart102715617.dvUWLDBhPU Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Friday, October 26, 2018 7:29:46 AM CDT Crocodile wrote: > Hi internals! > > I have this idea of improving the way to specify callbacks for good old PHP > functions. For instance, I have this piece of code: > > --------------- > array_filter($names, 'trim') > --------------- > > The callback function name is specified as a string, which makes it > not-so-obvious, although this is definitely a PHP way. An alternative would > be to rewrite this using a lambda: > > --------------- > array_filter($names, function($name) { return trim($name); }) > --------------- > > This is way more wordy, and I bet most of us will go for the first option. > > What if we had a more clear way of specifying those callbacks? I suggest > the following: > > --------------- > array_filter($names, function::trim) > --------------- > > It is, I believe, more clear then a simple string, just a bit more wordy, > and since "function" is a reserved word which never had anything to do with > "::", the lexer/parser could probably find a way to deal with this kind of > syntax (well, honestly, this part is totally unclear for me because I only > work with PHP from userland). > > Does anyone else find this could be a good addition? Or is it not worth > considering? Or maybe I am missing some obvious pitfalls? > > Cheers, > Victor I believe the proposal for short lambas (which should get resurrected at some point) would handle this case well enough as well as help a dozen other things. To wit: array_filter($names, |$x| ==> trim($x)) --Larry Garfield --nextPart102715617.dvUWLDBhPU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE/ph/GXfY8v0YwFBp4MMKwDFxYXcFAlvTNfcACgkQ4MMKwDFx YXcqBggA0z4H5apTxahgX5r4sJDpnDqnw6ILv1z8glGWJP3clRbFNLaVgsdMVqBz XncJBN17LZx0E7dCqRKy+Z5OFO2s8/IuLW0/h9dobRIoZc9EzK1knHtevQKVBFNb z7yTAsV9C88BsBBU3w8dOX9C0dLlVYvB9shgUNjME4EXiOSStqcA7Sz5MJcjSlom ceV95dJjn7NbRHem9KeBVy+CEsR+9FYCG8/CPOT7actOt86RrU79Rdg4ziUOmsz3 0btG1zjfPC0fybroom4szn6wrneDfswqAZtr2a1O9ZF8m/Y8fAJTOsFqot/hDBW+ PAleuZ7/8pFb9nys6rIyQQjPdXP1QA== =KhBG -----END PGP SIGNATURE----- --nextPart102715617.dvUWLDBhPU--