RE: [PHP] = 0 and = "0"

From: Date: Thu, 25 Oct 2001 14:53:35 +0000
Subject: RE: [PHP] = 0 and = "0"
Groups: php.general 
Request: Send a blank email to php-general+get-72269@lists.php.net to get a copy of this message
Hi John! > > > The integer 0 is equal to False, but not Null. > > > > Not quite true. 0 evaluates to false. They are not equal. > Try this: > [...] > > So be careful and try to think of 0 and false as distinct > and separate > > entities and you will avoid coding mistakes like this. > > Is this seen as a strength or a weakness of PHP.? According to my experience I'd say both, depending on the context... If you have to determin its type before using a variable and then, when changing it, have to do an explicit typecast, programming gets "cleaner" and in many cases more safe. On the other hand, if let's say false == 0 and true == 1, you can do nice things like arithmetic operations using booleans: $x = $y * (-1 * (abs($z) == $z)); Get the idea? > In C(++), direct comparisons to true/false are discouraged. > In other words, instead of this: > bool x; > if(x==true) ... > if(x==false) ... > > itt's always considered better to do this: > if(x) ... > if(!x) ... > > But PHP seems to require a direct comparison with false > in certain situations. Are there any cases where you need > to do a direct comparison with true? AFAIK it's only a matter of speed. Unary operators consume less time than binary ones... Correct me if I'm wrong. > Are you coming to Ottawa in the future? This I don't know... ;) Cheers, Kiko ----- It's not a bug, it's a feature. christoph starkmann mailto:kiko@nfq.de http://www.fh-augsburg.de/~kiko ICQ: 100601600 -----

« previous php.general (#72269) next »