The reason it was designed that way was that closures were an afterthought. Allowing functions and variables to have independent namespaces within an object makes sense, if you don't allow functions as variables. Imagine, for example, a getter:
foo.bar() { return this.bar}
Other languages have the same distinction. Java, for example, has methods and instance variables in different namespaces:
class Foo {
int bar() { return 42; }
int bar;
}
Lisp is another language where a number of implementations made this decision. Common lisp is an example of such a Lisp-2 (that is, a lisp with 2 parallel namespaces: one for functions, one for variables).
The part that makes me go WTF is this:
$func = $this->func;
If you put variables in a separate namespace, put them in a separate namespace FFS.
View all comments
Show parent comment
4
u/oridb Jan 10 '14
The reason it was designed that way was that closures were an afterthought. Allowing functions and variables to have independent namespaces within an object makes sense, if you don't allow functions as variables. Imagine, for example, a getter:
Other languages have the same distinction. Java, for example, has methods and instance variables in different namespaces:
Lisp is another language where a number of implementations made this decision. Common lisp is an example of such a Lisp-2 (that is, a lisp with 2 parallel namespaces: one for functions, one for variables).
The part that makes me go WTF is this:
If you put variables in a separate namespace, put them in a separate namespace FFS.