Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Honestly, I think this is all too complicated. In Javascript, when you look at a line like this:

  a=1
you have to guess in which scope it changes or creates the variable a. I prefer the way PHP is dealing with scope. You simply know that "a=1" is only affecting the current scope.


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...


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.


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.


> 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".


I never claimed that JavaScript was better, just more flexible. I agree that all the things you mentioned are pain points with JS.


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.


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.




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

Search: