note 34886 deleted from control-structures.switch by cmb
| From: | cmb@php.net | Date: | Thu, 25 Aug 2016 22:19:57 +0000 |
| Subject: | note 34886 deleted from control-structures.switch by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206390@lists.php.net to get a copy of this message | ||
Note Submitter: (cgibbard) student math uwaterloo ca
----
Just in reply to the comment about 2 digit numbers: something octal certainly is going on. Integer
literals prefixed with a "0", like in C and several other languages, are treated as octal.
Similarly, integer literals prefixed with "0x" are treated as hexadecimal. Seeing as this
is the case, 08 and 09 are not valid integer literals. It turns out that php treats them as 0 (it
would probably be better to fail with an error message, but it doesn't). Bottom line?
Don't prefix numbers with 0 in code unless you mean octal. Format them as you print them with
printf, like so: printf("%02u", $my_unsigned_int); or if you will, use sprintf to get a
string representation rather than printing on stdout.