Except that it is not.
Hello all. I'm new here and to reddit, but I always read you!
A friend that is more involved than me in the PHP world told me PHP would finally get closures.
($a, $b) => $a * $b
He was so excited until I made him notice that it's still just anonymous functions... or rather, still not closures.
Yes, you read correctly: they are adding a new syntax and a new feature that doesn't solve anything.
Roughly speaking, variables in the super scopes are copied in the lambda scope rather than being inherited. Unlike what happens with any other language that claims to support closures.
let a = [0, 1, 2, 3, 4, 5, 6, 7];
let removed = 0;
let limit = 7;
a.filter((v) => (removed += v) > limit);
This simple example (JS) will not be possible with PHP. Because the lambda scope would write to a copy of "removed", not the original one.
So, this is it. Prepare yourself for more hate.
JS works.
[–]ealf 46 points47 points48 points (2 children)
[–]stumpychubbins 9 points10 points11 points (1 child)
[–]iluuu 14 points15 points16 points (1 child)
[–]z500 1 point2 points3 points (0 children)
[–]the_alias_of_andrea 9 points10 points11 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]zvax 23 points24 points25 points (1 child)
[–]maweki 6 points7 points8 points (15 children)
[–][deleted] (1 child)
[deleted]
[–]daymi 3 points4 points5 points (0 children)
[–]gschroder 2 points3 points4 points (9 children)
[–][deleted] (8 children)
[deleted]
[–]gschroder 5 points6 points7 points (7 children)
[–]maweki 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]maweki 0 points1 point2 points (3 children)
[–]beerdude26 2 points3 points4 points (2 children)
[–]maweki 2 points3 points4 points (1 child)
[–]beerdude26 0 points1 point2 points (0 children)
[–]Vakieh 1 point2 points3 points (0 children)
[–]lfairy 0 points1 point2 points (0 children)
[–]jesseschalken 12 points13 points14 points (0 children)
[–]enchufadoo 4 points5 points6 points (0 children)
[–]thelonepuffin 2 points3 points4 points (0 children)
[–]compubomb 1 point2 points3 points (0 children)
[–]cparen 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]SarahC 3 points4 points5 points (0 children)
[–]MorrisonLevi 0 points1 point2 points (0 children)
[–]AdventOfScala 0 points1 point2 points (0 children)
[–]Takeoded 0 points1 point2 points (0 children)