note 64927 added to language.types.integer

From: Date: Sun, 23 Apr 2006 04:18:12 +0000
Subject: note 64927 added to language.types.integer
Groups: php.notes 
Request: Send a blank email to php-notes+get-109114@lists.php.net to get a copy of this message
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) ?> ---- Server IP: 66.163.161.117 Probable Submitter: 218.17.94.48 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.types.integer.php Edit -- http://master.php.net/note/edit/64927 Del: integrated -- http://master.php.net/note/delete/64927/integrated Del: useless -- http://master.php.net/note/delete/64927/useless Del: bad code -- http://master.php.net/note/delete/64927/bad+code Del: spam -- http://master.php.net/note/delete/64927/spam Del: non-english -- http://master.php.net/note/delete/64927/non-english Del: in docs -- http://master.php.net/note/delete/64927/in+docs Del: other reasons-- http://master.php.net/note/delete/64927 Reject -- http://master.php.net/note/reject/64927 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109114) next »