Doc #63027 [Opn->Csd]: dechex may convert numbers up to PHP_INT_MAX
| From: | aharvey@php.net | Date: | Mon, 10 Sep 2012 01:54:20 +0000 |
| Subject: | Doc #63027 [Opn->Csd]: dechex may convert numbers up to PHP_INT_MAX | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8842@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
Updated by: aharvey@php.net
Reported by: marc at ermshaus dot org
Summary: dechex may convert numbers up to PHP_INT_MAX
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: 64-bit
PHP Version: Irrelevant
-Assigned To:
+Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2012-09-10 01:54:04] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=327571
Log: Fix doc bug #63027 (dechex may convert numbers up to PHP_INT_MAX) by clarifying
that PHP treats the parameter as an unsigned int, and working through some of
the implications of that from a userland perspective.
------------------------------------------------------------------------
[2012-09-07 09:44:02] marc at ermshaus dot org
â[â¦] as PHP uses unsigned longs.â
Sorry, that should be *signed* longs.
------------------------------------------------------------------------
[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