php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61095 PHP can't add hex numbers
Submitted: 2012-02-15 15:32 UTC Modified: 2012-02-24 02:34 UTC
Votes:115
Avg. Score:4.1 ± 1.3
Reproduced:57 of 84 (67.9%)
Same Version:28 (49.1%)
Same OS:12 (21.1%)
From: tomek at przeslij dot pl Assigned: colder (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.10 OS: Windows XP
Private report: No CVE-ID: None
 [2012-02-15 15:32 UTC] tomek at przeslij dot pl
Description:
------------
These echoes 4:
echo (0x00+2);
echo (0x00+0x02);
but they should echo 2! This echoes 2 as expected:
echo (0x00 + 2);

Test script:
---------------
echo (0x00+2);

Expected result:
----------------
2

Actual result:
--------------
4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-15 15:54 UTC] anon at anon dot anon
That is fan-tastic!

http://i.imgur.com/uPC2b.gif
 [2012-02-15 16:24 UTC] nikic@php.net
Nice catch!

This can be fixed by adding a len == 0 check after the while loop in http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_scanner.l#1515 (and returning 0 in that case).
 [2012-02-15 16:55 UTC] colder@php.net
-Status: Open +Status: Assigned -Package: Math related +Package: Scripting Engine problem -Assigned To: +Assigned To: colder
 [2012-02-20 18:28 UTC] colder@php.net
Automatic comment from SVN on behalf of colder
Revision: http://svn.php.net/viewvc/?view=revision&revision=323394
Log: Fix #61095 (Lexing 0x0*+<NUM> incorrectly)
 [2012-02-23 15:55 UTC] lepidosteus+phpbug at gmail dot com
Correct behavior for me in 5.3.3-7+squeeze3

$ php -r "var_dump(0x02+0x00);"
int(2)
$ php -r "var_dump(0x02+0);"
int(2)
$ php -r "var_dump('0x02'+0);"
int(2)
 [2012-02-23 15:56 UTC] lepidosteus+phpbug at gmail dot com
Sorry, forget my previous comment, I misunderstood the issue
 [2012-02-23 20:14 UTC] phpbug at vincent dot sh
Lexer level ? Russian. http://goo.gl/eqxZ8
 [2012-02-23 20:40 UTC] balthasar dot reuter at cs dot fau dot de
Behavior reproduced:

$ php -r 'echo (0x00+2);echo "\n";'
4
$ php -r 'echo (0x00+ 2);echo "\n";'
2
$ php -r 'echo (0x00 + 2);echo "\n";'
2
$ php -r 'echo (0x00 +2);echo "\n";'
4
$ php -v
PHP 5.3.8 (cli) (built: Dec  5 2011 21:24:09) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

Mac OS X 10.6.8
 [2012-02-23 21:55 UTC] jordan dot sherer at definition6 dot com
Reproduced, but after adding spaces around the + it works as intended.

$ php -r 'echo (0x00+2);echo "\n";'
4

$ php -r 'echo (0x00 + 2);echo "\n";'
2

$ php -v
PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
 [2012-02-23 22:53 UTC] yk4ever at gmail dot com
It is already fixed in the trunk and relevant version branches.
 [2012-02-24 01:16 UTC] admin at jesus dot de
NOT reproduced in older version:

# php -r 'echo (0x00+2);echo "\n";'
2
# php -r 'echo (0x00+ 2);echo "\n";'
2
# php -r 'echo (0x00 + 2);echo "\n";'
2
# php -r 'echo (0x00 +2);echo "\n";'
2
# php -v
PHP 5.2.6-1+lenny13 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul  1 2011 17:03:36)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
 [2012-02-24 02:34 UTC] colder@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-02-24 02:34 UTC] colder@php.net
-Status: Assigned +Status: Closed
 [2012-04-18 09:46 UTC] laruence@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eefefddc0ee0dadc37b1bf05cada8685e546461e
Log: Fix #61095 (Lexing 0x0*+<NUM> incorrectly)
 [2012-07-24 23:37 UTC] rasmus@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eefefddc0ee0dadc37b1bf05cada8685e546461e
Log: Fix #61095 (Lexing 0x0*+<NUM> incorrectly)
 [2012-10-08 06:05 UTC] user585859 at rediffmail dot com
php -r 'echo (0x00+2);echo "\n";'
4
$ php -r 'echo (0x00+ 2);echo "\n";'
2
$ php -r 'echo (0x00 + 2);echo "\n";'
2
$ php -r 'echo (0x00 +2);echo "\n";'
4
$ php -v
http://goo.gl/MGM87
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eefefddc0ee0dadc37b1bf05cada8685e546461e
Log: Fix #61095 (Lexing 0x0*+<NUM> incorrectly)
 [2019-04-05 13:12 UTC] adityakin9 at gmail dot com
php -r 'echo (0x00+2);echo "\n";'
4
$ php -r 'echo (0x00+ 2);echo "\n";'
2
$ php -r 'echo (0x00 + 2);echo "\n";'
2
$ php -r 'echo (0x00 +2);echo "\n";'
4
$ php -v
https://bit.ly/2IbnZKk
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC