Re: Arrow function expressions in PHP

From: Date: Thu, 01 Oct 2015 10:48:52 +0000
Subject: Re: Arrow function expressions in PHP
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-88600@lists.php.net to get a copy of this message
Levi Morrison wrote on 01/10/2015 04:06:
I'm going to ask everyone to stop saying that auto-closing is bad unless they also provide a demonstration of why it was bad.
Please see my e-mail from last night, or Rasmus's in the original thread. It is "bad" (or, controversial) because it is a fundamental change to PHP's scoping rules, which currently treat all variables denoted by "$foo" as local to the current function, without exception.
I'm also going to ask everyone to stop suggesting new syntax for importing variables. If use() is a pain then auto-importing the used variables is a good solution. If it's not a pain why are you suggesting new syntax?
Because the feature is being described as "short closures", or as a new syntax, so people are looking for ways to make closures shorter without changing the functionality. If auto-capture is the main feature you are interested in, and syntax just a by-product, then it might be sensible to make that clear. As a straw man, it would be possible to have auto-capture closures with no new syntax at all, e.g. function($x) use(*) { return $x * $y; } It's perfectly reasonable to want both a shorter syntax and a different capture behaviour; but it also seems perfectly reasonable to want a shorter syntax with the same functionality as the current one, just as we have with [] vs array(). Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#88600) next »