[UPHPU] simple question

Jennifer Wollesen jwollese at gmail.com
Wed Apr 21 15:50:56 MDT 2010


Because you are doing a print, and print is expecting a string argument, your bool will be converted to a string. And when converting a bool to a string, PHP converts true to "1" and false to "":
http://us3.php.net/manual/en/language.types.string.php#language.types.string.casting

If you were converting to an int, true would be 1 and false would be 0:
http://us3.php.net/manual/en/language.types.integer.php#language.types.integer.casting

You could do var_dump($writePriv) if you want to debug the value of the variable without converting it. Or, if you really want to print out the zero, you could do something like:
print "<br /> write priv is " . intval($writePriv);



On Apr 21, 2010, at 3:12 PM, Merrill Oveson wrote:

> I have the following code:
> 
> function writePriv ($x) {
>    if ($y== 0) {
>       return TRUE;
>    } else {
>       return FALSE;
>    }
> 
> }
> 
> $writePriv = writePriv('w');
> if ($writePriv == FALSE) { print "false!!!"; }
> print "<br /> write priv is $writePriv";
> 
> 
> The output is:
> 
> false!!!
> write priv is
> 
> ______________
> When writePriv returns TRUE
> the output is:
> 
> write priv is 1.
> 
> 
> My question: why when the function returns FALSE, don't I get a 0 (zero)?
> 
> Thanks
> 
> Merrill
> 
> _______________________________________________
> 
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net



More information about the UPHPU mailing list