|  | Posted by Bent Stigsen on 07/18/06 05:59 
Chung Leong wrote:> Bent Stigsen wrote:
 >> It's quite clearly stated in the manual, no problem there. I just
 >> don't understand the choice of behavior.
 >>
 >> It is the concept of "isset", which I like to take literally.
 >> When I set the variable to null, causing the variable to appear in
 >> $GLOBALS, why should "isset" return false?
 >>
 >> I understand the behavior, not the choice.
 >
 > Part of the reason is the way the global and static keyword was
 > implemented. These are operators, not declarations. When you use them
 > on variables they create entries in the current symbol table. Thus if
 > isset() behaves as you described, it'll always return true in the
 > following:
 >
 > <?
 >
 > function bobo() {
 >    static $the_clown;
 >    if(isset($the_clown)) {
 >    }
 > }
 >
 > ?>
 >
 > which wouldn't be rather unintuitive, since you never actually set the
 > variable.
 
 Yes, I guess it would, but I would say creating them in the first
 place is unintuitive too. At least for global.
 e.g.:
 
 <?php
 echo $a;  //generates error, $a not in $GLOBALS
 foo();
 echo $a;  //no error, $a is now in $GLOBALS
 
 function foo() {
 global $a;
 echo $a;   //no error
 }
 ?>
 
 It is not that I in a tight spot haven't made that kind of choice of
 getting a feature at the cost of a less sensible behavior, in order to
 avoid the need to rewrite a lot of code. But personally I would rather
 just (temporarily) accept the odd effect of the modifiers, rather than
 seeing other functions being adapted to it, if that is the case.
 
 --
 /Bent
  Navigation: [Reply to this message] |