Re: [RFC] Short Closures 2, aka auto-capture take 3

From: Date: Mon, 13 Jun 2022 12:12:44 +0000
Subject: Re: [RFC] Short Closures 2, aka auto-capture take 3
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-117929@lists.php.net to get a copy of this message
On lundi 13 juin 2022 12:28:17 CEST Robert Landers wrote: > From a maintainer and code review aspect, I prefer the longer syntax > because it is 100% clear on which variables are being closed over and > utilized in the anonymous function. fn($x) => $x + $y is pretty clear > that $y is being pulled in from an outer scope but if you start > getting into longer ones, it can get non-obvious pretty quickly... > > $func = fn($x) { > $y[] = $x; > // do some stuff > return $y; > } > > If $y is pulled from the outside scope, it may or may not be > intentional but hopefully, it is an array. If anyone uses the name $y > outside the lambda, this code may subtly break. This is true for any function that uses the array-append operator on an undefined variable.

« previous php.internals (#117929) next »