RE: [PHP] damned "false"
| From: | Craig Vincent | Date: | Sat, 20 Jul 2002 19:27:05 +0000 |
| Subject: | RE: [PHP] damned "false" | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108670@lists.php.net to get a copy of this message | ||
> I am not very happy how generaly boolean comparison is solved in
> PHP...but I checked different stuff and like this shouldn't be:
> ----
> <?
> $a="null";
> if ($a="dwa") { // one sign = so it is OK
> echo "OK";
> }
> if ($a=true) {
> echo "OK";
> }
> if ($a=false) {
> echo "OK"; //but it is not written!!!!!!!
> }
> ?>
> I tested it in PHP4.2.0 (LINUX)
Well your problem is you're not doing ANY comparisons. Your if statements
are assigning values. Not comparing...to compare you need to use == , not
just =. With your current statements, each if statement will always be
true, just the value of $a changes at each if.
<?
$a="null";
if ($a=="dwa") { // one sign = so it is OK
echo "OK";
}
if ($a==true) {
echo "OK";
}
if ($a==false) {
echo "OK"; //but it is not written!!!!!!!
}
?>
Is what you need. Also for me boolean checks in my opinion are much
simplier if you use 1-0 for the comparison (but use what you need, I don't
know your entire code).
Sincerely,
Craig Vincent