php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52950 Wrong implicit conversion of strings containing hexadecimal numbers to int
Submitted: 2010-09-29 10:49 UTC Modified: 2015-02-08 10:23 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: confik at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0 OS: Linux 2.6.32 Ubuntu 10.04/i686
Private report: No CVE-ID: None
 [2010-09-29 10:49 UTC] confik at gmail dot com
Description:
------------
If string contains hexadecimal number, such as '0x05' it correctly explicitly 
casts to integer(resulting zero):
php > var_dump((int) '0x05');
int(0)
but incorrectly casts implicitly (resulting its value, 5)
php > var_dump(1 * '0x05');
int(5)

Same for floats:

php > var_dump((float) '0xffffffffff');
float(0)
php > var_dump(1 * '0xffffffffff');
float(1099511627775)

P.S.: Tests were made on x86 (i686) Linux machine.


Test script:
---------------
<?php
var_dump(1 * '0x05');
var_dump(1 * '0xffffffffff');




Expected result:
----------------
int(0)
float(0)

Actual result:
--------------
int(5)
float(1099511627775)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-15 18:33 UTC] felipe@php.net
-Package: Strings related +Package: Scripting Engine problem
 [2013-05-18 12:33 UTC] cmbecker69 at gmx dot de
IMO the behavior of the implicit type juggling is correct,
and the result of the explicit type cast is erroneous in this regard.

Anyway, both results should match.
 [2015-02-08 10:23 UTC] nikic@php.net
-Status: Open +Status: Closed -PHP Version: 5.3.3 +PHP Version: 7.0.0 -Assigned To: +Assigned To: nikic
 [2015-02-08 10:23 UTC] nikic@php.net
Fixed in PHP 7, by removing hex-string support in the cases where it existed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 15:01:32 2024 UTC