RE: [PHP] Found a PHP bug!!!!!!!!!
| From: | Cal Evans | Date: | Mon, 27 Jan 2003 20:26:37 +0000 |
| Subject: | RE: [PHP] Found a PHP bug!!!!!!!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133285@lists.php.net to get a copy of this message | ||
Scott,
Because "8" != 8. "8" (and "08") is a string with the numerals
representing
the number eight. It is not the number eight. (think back to basic math, the
difference between a number and a numeral)
PHP does some conversions for you automatically but that just saves you from
yourself. (Personally, I wish it wouldn't. People have more trouble
*because* of the automatic conversions than they would if they had to do the
converting themselves.)
To keep from running into this simply do the conversions yourself before you
do comparisons.
intval("08")==8
=C=
*
* Cal Evans
* Stay plugged into your audience.
* http://www.christianperformer.com
*
-----Original Message-----
From: Scott Fletcher [mailto:scott@abcoa.com]
Sent: Monday, January 27, 2003 2:14 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Found a PHP bug!!!!!!!!!
I don't see why a string wouldn't work when I use "08" (string) and match it
against the integer 8, or 08.
"Kirk Johnson" <kjohnson@zootweb.com> wrote in message
news:B11731D518B5D61183C700A0C98BE0D9FFBE5D@chef...
>
> > -----Original Message-----
> > From: Scott Fletcher [mailto:scott@abcoa.com]
> >
> > Found a PHP bug, I'm using PHP version 4.2.3. I have been
> > struggling with
> > why PHP code failed to work with the month is August or
> > September
>
> I stumbled into this one a short while ago myself. It is not a bug, but a
> feature! ;) When passing values of 08 or 09 (Aug and Sep), PHP interprets
> them as octal numbers (because of the leading 0). However, 08 and 09 are
> invalid octal numbers, so PHP converts them to zero.
>
> The fixes are numerous:
> - remove the leading zero;
> - add zero to them before passing (addition forces a type conversion to
> int);
> - force a type conversion to integer using (int);
> - quote them (when PHP converts a string to an integer, it removes the
> leading zero);
>
> Kirk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php