Re: [PHP] possible bug (string equality to zero)?
Hi, > Is it a bug that ($var == 0) is always true for any string $var? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Check this out! http://us3.php.net/manual/en/types.comparisons.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible bug (string equality to zero)?
Christopher J. Bottaro wrote: Is it a bug that ($var == 0) is always true for any string $var? For any string? How about the string 5? :-) PHP tries to help you out, but there's not much it can do when you ask it to compare a string like 'foo' to an integer. It scans your string from left to right and uses the leading numbers to create the integer. For example, 53chris is 53, but chris53 is 0 (no leading numbers). Hope that helps. Chris -- Chris Shiflett Brain Bulb, The PHP Consultancy http://brainbulb.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible bug (string equality to zero)?
> [snip] > Is it a bug that ($var == 0) is always true for any string $var? > [/snip] > > You are comparing a string to an integer. Right. This is clearly documented at http://www.php.net/operators.comparison -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible bug (string equality to zero)?
No, Christopher, that is not a bug. As long as the var is empty, and if you try to compare with 0, or false, it will report true in the comparison because the variable does not contain anything, which will mean false for a boolean and 0 for a variable. If you are attempting to discover if a string contains data, use empty() instead. You can also check if the string is null or actual zero (0). Regards, Torgny Christopher J. Bottaro wrote: >Is it a bug that ($var == 0) is always true for any string $var? > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] possible bug (string equality to zero)?
[snip] Is it a bug that ($var == 0) is always true for any string $var? [/snip] You are comparing a string to an integer. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php