News for hackers. Stuff that matters.
Re:JavaScript: what is "this"? by IgorPartola on Sunday March 21, 2010 @03:43PM (#1208438)
Which is why PHP is so much less flexible than JS. Also try this:

  $a = 1;
  function qqq() {
    global $a;
    unset( $a );
  }
  qqq();
  var_dump( $a );
P.S.: In PHP 5.1.6 calling unset() actually increases memory usage...
Re:JavaScript: what is "this"? by devinj on Sunday March 21, 2010 @03:52PM (#1208453)
I find it hard to believe that the largest cause (or even a significant cause) in the difference of flexibility of two languages is whether or not you can declare variables to belong to a given scope, and to which scope they default to.
Re:JavaScript: what is "this"? by IgorPartola on Sunday March 21, 2010 @07:15PM (#1208818)
I was referring more to the "feel" of the language rather than the fact that this individual feature is the single reason for why JavaScript is more flexible.
Re:JavaScript: what is "this"? by WilliamLP on Sunday March 21, 2010 @04:57PM (#1208573)
> Which is why PHP is so much less flexible than JS.

When running, I want enough flexibility to move freely but not so much that my knees break. When programming, I'd like to rely on "undefined" not being 6, and I'd even like to have a reasonable built in dictionary type that other code can't extend to add keys to by default, or overwrite "hasOwnProperty".

Re:JavaScript: what is "this"? by IgorPartola on Sunday March 21, 2010 @07:18PM (#1208822)
I never claimed that JavaScript was better, just more flexible. I agree that all the things you mentioned are pain points with JS.
Re:JavaScript: what is "this"? by rimantas on Sunday March 21, 2010 @04:11PM (#1208487)
global $a in PHP is just another way to write $a =& $GLOBALS['a'];

I.e. you just create reference to a global variable. Unsetting reference just breaks the tie between variable name and content.

Re:JavaScript: what is "this"? by IgorPartola on Sunday March 21, 2010 @07:14PM (#1208814)
Exactly, which means that unset( $a ) is not the same thing as unset( $GLOBALS['a'] ). It makes perfect sense, just not a kind of thing you might not expect at first.