Doc #63027 [NEW]: dechex may convert numbers up to PHP_INT_MAX

From: Date: Fri, 07 Sep 2012 08:53:11 +0000
Subject: Doc #63027 [NEW]: dechex may convert numbers up to PHP_INT_MAX
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8819@lists.php.net to get a copy of this message
From: marc at ermshaus dot org Operating system: 64-bit PHP version: Irrelevant Package: Documentation problem Bug Type: Documentation Problem Bug description:dechex may convert numbers up to PHP_INT_MAX Description: ------------ The range of this function seems to be platform dependent and contain the whole range of the C long type. The documentation states: “Returns a string containing a hexadecimal representation of the given number argument. The largest number that can be converted is 4294967295 in decimal resulting to "ffffffff".” Technically, that would be the interval [-PHP_INT_MAX - 1, PHP_INT_MAX] as PHP uses unsigned longs. Implementation details: - dechex: https://github.com/php/php-src/blob/b47d6b32ba8d6dc1b9d1fc91a83eef29a28363c5/ext/standard/math.c#L1047 Calls: - convert_to_long_ex: https://github.com/php/php-src/blob/b47d6b32ba8d6dc1b9d1fc91a83eef29a28363c5/Zend/zend_operators.h#L398 - convert_to_ex_master: https://github.com/php/php-src/blob/b47d6b32ba8d6dc1b9d1fc91a83eef29a28363c5/Zend/zend_operators.h#L355 - convert_to_long: https://github.com/php/php-src/blob/b47d6b32ba8d6dc1b9d1fc91a83eef29a28363c5/Zend/zend_operators.c#L324 - convert_to_long_base: https://github.com/php/php-src/blob/b47d6b32ba8d6dc1b9d1fc91a83eef29a28363c5/Zend/zend_operators.c#L332 Then strtol from stdlib would be called which returns a long. Test script: --------------- var_dump( PHP_INT_SIZE, PHP_INT_MAX, dechex(PHP_INT_MAX), dechex(-PHP_INT_MAX - 1), dechex(-1) ); int(8) int(9223372036854775807) string(16) "7fffffffffffffff" string(16) "8000000000000000" string(16) "ffffffffffffffff" -- Edit bug report at https://bugs.php.net/bug.php?id=63027&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63027&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63027&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63027&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63027&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=63027&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=63027&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63027&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63027&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63027&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63027&r=support Expected behavior: https://bugs.php.net/fix.php?id=63027&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63027&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63027&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63027&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63027&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63027&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63027&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63027&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63027&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63027&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63027&r=mysqlcfg

« previous php.doc.bugs (#8819) next »