note 64927 deleted from language.types.integer by bjori
| From: | bjori@php.net | Date: | Sun, 23 Apr 2006 09:07:57 +0000 |
| Subject: | note 64927 deleted from language.types.integer by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109137@lists.php.net to get a copy of this message | ||
Note Submitter:
----
It seems there is a bug in converting hexadecimals in strings to integers with the intval() function
and (int) casting, but not with type juggling:
<?php
var_dump(intval("0x31")); // int(0) (should be 49)
var_dump((int) "0x31"); // int(0) (should be 49)
var_dump(1 + "0x31"); // int(50) (correct--i.e., 1+49)
?>
Though they are not treated as invalid numeric data (which would result in a 0 value), octals are
not handled correctly in string to integer conversions (they are handled after the preceding 0 as
though they were decimal integers):
<?php
var_dump(intval("031")); // int(31) (should be 26)
var_dump((int) "031"); // int(31) (should be 26)
var_dump(1 + "031"); // int(32) (should be 26)
?>