Hacker Newsnew | past | comments | ask | show | jobs | submit | jblotus's commentslogin

Here is a thread with some of our observations.

https://forums.aws.amazon.com/thread.jspa?threadID=261421&ts...


Not sure what your statement means.


It's a spiteful ad-hominen, that's all you need to know about the parent comment.

As for the article, it's an internet classic on a quite basic concept, and was included in Joel Spolsky's best "software writing" collection.


just awesome


interesting, for those of us who have been using apc for years.


author here.

<?php $a = 1; /* global scope */

function test() { echo $a }

test();

in javascript, $a would be 1 but in PHP it is undefined and won't produce output,


after thinking about it for a while, I was misrepresenting what block scope actually was and removed those references in the post.


thanks for the help


i've also run into this, usually through double event binding


author here, it wasn't about hiding private variables. i was demonstrating using closures to avoid global namespace collisions which i think is generally a big problem for beginners.


i believe you mean using functions, not closures. your post doesn't seem to have the same misnomer, and simply explains lexical function scope. it doesn't seem to touch on the closure, while your parent comment does.


well, functions close over scope no matter what you call them.


not exactly. closures close over scope. functions alone simply create a new scope. these concepts are not synonymous.

if your function doesn't return another function, the references from that function are deallocated once the function has executed.

when your function returns a function (a "closure"), the inner function closes over the variables of the outer function, maintaining references to it's context as long as you maintain a reference to the closure.


ok i see your point. i conflated the terms function and closure in this case.


thanks for reading


or both for next level mode!


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

Search: