Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35135 invoked from network); 17 Jun 2019 17:25:55 -0000 Received: from unknown (HELO wout3-smtp.messagingengine.com) (64.147.123.19) by pb1.pair.com with SMTP; 17 Jun 2019 17:25:55 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 6BDE387D; Mon, 17 Jun 2019 10:40:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 17 Jun 2019 10:40:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; h=from:message-id:content-type:mime-version:subject:date :in-reply-to:cc:to:references; s=fm2; bh=bmk6UPuGi9FPeMZJ1XFgW+8 7crOOQpSNt/xP2P3lDX4=; b=PvrOAKJz6EbD1GUUqzBtTHxsLrv/UhZg5zMKAQD QMqNvE+wBfPoElcnQMWWrz12f5O3tFrQxpwqtcYSdNjoNB1t7gUtC1T8gmbtSJGH YRXVRHIE3WFlpe+f8rz7Jkv1dTkjARNfhMU8bH+u3r3r3n1yaQmoNeWW2zgIZgzx Zw3QIzYeEQgWeVe21hHW41p2o8PmCZXMH/byvfzrN5k8U1ZxIs58j0Peve2FMuSG /nw17nutCKcFX4208sXbjM+xgRxnOWLmgzs9LOyYdkgBq/dpUM0XxUX6s+KrzGW6 vR6sIJWAiY17LadOATubbKqTqjuLXOzIn7fm9lkkhcMVZRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm3; bh=bmk6UP uGi9FPeMZJ1XFgW+87crOOQpSNt/xP2P3lDX4=; b=pR8/o2M/p65vRxEuHTtNw3 yOV26/ETlLl/aeulc8cR9EALxnKuRvAREORcWgvWpzb6lygrWDXYfRNnZRc5W68i G6L/4FpYWH/q/0n6ecQ2NAIqnvcMaYyoxwiyhndT/KCqszBfvDn5G19A60sLoEfT nNOp/yi+YCaTh9EqYGeUhZMTX+VLZHFtePdhxeIbz+pqrpQxH5GosGSfyd259AnA 0ONRDE8BfugpTjeYYgBiI2RDnxWRESaE+Q6P/kwlyD8ho47miV+JhKJNWc4FQM02 ElZoVF3yOnlcNiii/ZkMaPQ0gHlR/n/tXFaP7C8mUssZZmSMpi18wO35Aj0Y5lVA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudeijedgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffktgggufffjgfvfhfosehgtdhmrehhtdejnecuhfhrohhmpeeuvghnucft rghmshgvhicuoegsvghnsegsvghnrhgrmhhsvgihrdgtohhmqeenucffohhmrghinhepph hhphdrnhgvthenucfkphepleeirdeiuddrudejtddrhedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpegsvghnsegsvghnrhgrmhhsvgihrdgtohhmnecuvehluhhsthgvrhfuihiivg eptd X-ME-Proxy: Received: from [10.10.42.56] (h96-61-170-50.lvrgtn.dsl.dynamic.tds.net [96.61.170.50]) by mail.messagingengine.com (Postfix) with ESMTPA id A9B41380086; Mon, 17 Jun 2019 10:40:02 -0400 (EDT) Message-ID: Content-Type: multipart/signed; boundary="Apple-Mail=_B0979F56-FEAB-4D9B-9216-2579AE828808"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 17 Jun 2019 09:40:01 -0500 In-Reply-To: Cc: internals@lists.php.net To: Mark Randall References: X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV][RFC] Alternative "use" syntax for Closures From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_B0979F56-FEAB-4D9B-9216-2579AE828808 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 16, 2019, at 07:04, Mark Randall wrote: >=20 > On 15/06/2019 22:53, Wes wrote: >> Hello PHP, I just published >> https://wiki.php.net/rfc/alternative-closure-use-syntax >> I would love your opinion on this >=20 > I'm not overly fond of it myself because I think it could make it = slightly more difficult to parse in my brain. >=20 > If there was a: >=20 > $x =3D 0; > $y =3D 1; >=20 > $closure =3D function() use (...) { >=20 > }; >=20 > Where "use (...)" would auto-capture all of the used variables in a = similar manner to short closures, that would certainly save a bit of = time. Would this mean that all variables in the =E2=80=9Cparent" are now = available in the =E2=80=9Cchild?=E2=80=9D This seems like it could = result in some unexpected surprises as scope =E2=80=9Cleaks=E2=80=9D = across these boundaries. As others have pointed out, I think there are better ways to solve the = problem illustrated in the RFC. With a bit more code, you can use an = anonymous object to accomplish the same thing, without any use = statements. $anonymousObject =3D new class( $var1, $var2, $var3, $var4 ) { private $v1, $v2, $v3, $v4; public function __construct( $importVariable1, &$importVariable2, $importVariable3, &$importVariable4 ) { $this->v1 =3D $importVariable1; $this->v2 =3D $importVariable2; $this->v3 =3D $importVariable3; $this->v4 =3D $importVariable4; } public function __invoke( ArgumentType $argument1, ArgumentType $argument2, ArgumentType $argument3, ArgumentType $argument4 ): ReturnType { // do whatever you need here, accessing $this->v1, etc. } }; However, I would argue that, if you find yourself needing to do = something this complex, it=E2=80=99s probably best to move it into its = own named class so that it=E2=80=99s easier to test and maintain. -Ben --Apple-Mail=_B0979F56-FEAB-4D9B-9216-2579AE828808 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCXQemQQAKCRCwLZeYnIwH G9jyAP4vmt5ZeJ8GhRZSZ9edo5iLrsaLUOzWXmzw8E/AlJhdnAD+LXdybsUM0I2B 3TY8c9OgqZJE5oVC1ljz8RHmEjeTfOI= =LmVj -----END PGP SIGNATURE----- --Apple-Mail=_B0979F56-FEAB-4D9B-9216-2579AE828808--