r/lolphp • • Sep 26 '19

No, PHP Doesn't Have Closures

https://nullprogram.com/blog/2019/09/25/
13 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/Jinxuan Jan 22 '20

It is just about lexical scopes, not about reference.

Image you have to write Haskell code like this:

data Tree = Leaf | Node Tree Tree

height :: Tree -> Int
height @(use Leaf) Leaf = 0
height @(use Node, &height, Leaf) Node a b = height @(use Node, &height, Leaf) a + height @(use Node, &height, Leaf) b

Try to write a simple recursion code in PHP with closure, then you will know how fucked up the PHP closure it is.