Bug #69906 [Asn->Nab]: chr() behavior difference between 32- and 64-bit bulids
Edit report at https://bugs.php.net/bug.php?id=69906&edit=1
ID: 69906
Updated by: ab@php.net
Reported by: ab@php.net
Summary: chr() behavior difference between 32- and 64-bit
bulids
-Status: Assigned
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: any
PHP Version: 7.0.0alpha1
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
Hi Bob,
yeah, i was investigating on this but didn't come to update the ticket. You're right,
while it's an issue :)
I first thought it's an issue on 64-bit, now it looks the issue is on 32-bit (expected should
deliver int(173)). Namely - on 32-bit the argument that overflows PHP_INT_MAX will be just truncated
to zero (read as 'l' by ZPP or alike). While I saw that there could be a way to fix this
on 32-bit, it would be too expensive to be justified. Thus, probably best is to leave it as is, a
cast to int should do more or less correct job on this.
So kinda marking this as no bug.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-06-23 20:15:04] bwoebi@php.net
May I request to not have that changed?
That's technically a BC break, because there's code out there relying on chr() implicitly
doing & 0xFF on the passed param.
I think that's rather a doc bug?
------------------------------------------------------------------------
[2015-06-23 07:22:19] ab@php.net
Description:
------------
When passing an integer that overflows PHP_INT_MAX in 32-bit, the behavior of chr() differs. The
documentation currently doesn't define what should happen in this situation, the only statement
is that chr() expects an ASCII code. chr() should ensure the input is in the valid range, thus
making the behavior consistent between 32- and 64-bit.
Test script:
---------------
Debug\php.exe -r "$a = chr(2632627629); var_dump($a, ord($a));"
string(1) " "
int(0)
x64\Debug\php.exe -r "$a = chr(2632627629); var_dump($a, ord($a));"
string(1) "¡"
int(173)
Expected result:
----------------
string(1) " "
int(0)
Actual result:
--------------
Different behavior depending on 32- or 64-bit build.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69906&edit=1
Thread (4 messages)