4 ms·
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
by icode 17y ago
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.
- IgorPartola 17y agoWhich 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...
- devinj 17y agoI 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.
- IgorPartola 17y agoI 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.
- rimantas 17y agoglobal $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.
- IgorPartola 17y agoExactly, 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.
- WilliamLP 17y ago> 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".
- IgorPartola 17y agoI never claimed that JavaScript was better, just more flexible. I agree that all the things you mentioned are pain points with JS.