On Thu, Mar 25, 2021 at 10:38 AM Olle Härstedt <olleharst...@gmail.com> wrote:
> 2021-03-25 15:23 GMT+01:00, Christian Schneider <cschn...@cschneid.com>: > > Am 25.03.2021 um 14:29 schrieb Mark Randall <marand...@php.net>: > >> On 25/03/2021 09:28, Rowan Tommins wrote: > >>> That's not quite what I meant. I meant that you can't say "capture by > >>> default, but this variable is definitely local". > >> > >> I think if there's one argument against, this would be it, but IMHO it > is > >> a weakness in PHP as a whole. > > > > I'm not sure if I misunderstand what you're saying but to me it is one of > > the greatest things about PHP that everything is local by default (minus > a > > narrow set of well-known and easily enough recognizable things). > > > >> The solution would be adding JS-like let / const statements. Which would > >> be a benefit to other things too. > > > > > > I disagree that this is the solution. I think JS had to add var and later > > let because of the unfortunate decision to have C-like scoping rules. > > Making scoping in PHP more complex to be able to repeat this mistake in > some > > form seems ill-advised to me. > > > > - Chris > > You could make the change that *all* variables are now block-scoped, > not function-scoped. That would make auto-capture less dangerous, but > I don't know how much code it would break. > > The BC implications would be huge, not to mention that it wouldn't be a good idea anyway (at least in my opinion). The following would no longer work: if($check){ $match = true; } else { $match = false; } //stuff if($match){...} Yes, that could be done in a way that works with block scoping, but the fact that PHP has never been blocked scoped means there would be a LOT of code that would break if it was. > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > -- Chase Peeler chasepee...@gmail.com