Re: Found a PHP bug!!!!!!!!!

From: Date: Mon, 27 Jan 2003 20:27:39 +0000
Subject: Re: Found a PHP bug!!!!!!!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-133286@lists.php.net to get a copy of this message
Re: [PHP] Found a PHP bug!!!!!!!!! uh oh...
I don't see why a string wouldn't work when I use "08" (string) and match it against the integer 8, or 08.
They're just different types. Normally PHP is veeery flexible with types, like javascript, but it just can't be flexible for you here because it needs to choose the most logic to the entire pool of programmers, and then "08" = a string 8 = a decimal integer 08 = by definition an impossible octal integer, so 0. Since you cannot tell PHP that $var is of a certain type like in [other] programming languages, for example you want it to be treated as an integer, PHP will handle it as what seems to be the most logic. You can try to use intval (does not alter a variable, only the value as it is used in a calculation or an if() statement) or settype (alters the variable).
"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


« previous php.general (#133286) next »