Hacker News new | past | comments | ask | show | jobs | submit login

Oh, did I get downvoted because the create_function function actually does create lambdas?



Well, create_function() does create a new, randomly-named function in the global scope, meaning that it will not fall out scope at any point, so that you can use it as a real lambda. And because of the way that create_function() uses a string to build the function contents, by generating a new function everytime you call it, in effect you get "real" closures too. It could most certainly be improved to be more "natural" and complete, but that's probably going to break backward-compati.... oh wait, this is PHP.


Except that without scope inheritance, the "closures" created with create_function are kind of useless, and since functions are created in the global scope and thus are not garbage collected, creating new ones each time it is called ends up eating a lot of memory. This makes create_function largely useless, I don't know anyone who uses it; it's often better to just define the function globally yourself anyway and avoid the cost of run-time parser invocation, which is the same cost as using eval. In fact, create_function is implemented in terms of eval.

So you get a bunch of drawbacks and none of the real benefits, plus misrepresentation in the documentation.

Which necessitates this patch, which includes syntax changes, of course. This can only, ahem, be better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: