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

From: Date: Fri, 07 Sep 2012 09:44:02 +0000
Subject: Doc #63027 [Opn]: dechex may convert numbers up to PHP_INT_MAX
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8820@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63027&edit=1 ID: 63027 User updated by: marc at ermshaus dot org Reported by: marc at ermshaus dot org Summary: dechex may convert numbers up to PHP_INT_MAX Status: Open Type: Documentation Problem Package: Documentation problem Operating System: 64-bit PHP Version: Irrelevant Block user comment: N Private report: N New Comment: “[…] as PHP uses unsigned longs.” Sorry, that should be *signed* longs. Previous Comments: ------------------------------------------------------------------------ [2012-09-07 08:53:11] marc at ermshaus dot org 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 this bug report at https://bugs.php.net/bug.php?id=63027&edit=1

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