|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26624 cannot get the right value when i use + operator
Submitted: 2003-12-15 02:45 UTC Modified: 2003-12-15 04:08 UTC
From: mlsx at cie dot xtu dot edu dot cn Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.3 OS: windows server 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mlsx at cie dot xtu dot edu dot cn
New email:
PHP Version: OS:


 [2003-12-15 02:45 UTC] mlsx at cie dot xtu dot edu dot cn
first i define a is 8 and b is 6.
When i use echo "a+b=".$a+$b."<br>"; 
the MS IE show the result is 2.
While i use echo "a+b="; echo $a+$b."<br>";
the result is correct!
the same result when use "-" operator  use a line command.
but the result is correct when i use * and /
i cannnot fix it!

Reproduce code:
$a = 8;
$b = 2;
$c = 3;
echo "a+b=".$a+$b."<br>";
echo "a-b=".$a-$b."<br>";
echo "a*b=".$a*$b."<br>";
echo "a/b=".$a/$b."<br>";
echo "a%c=".$a%$c."<br>";
echo "a++ is ".$a++;

Expected result:
a++ is 8 

Actual result:
a++ is 8 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-15 03:56 UTC] benjcarson at digitaljunkies dot ca
I believe you need to put the math expression in parentheses because '.' and '+' have the same precedence.  What is happening is that you end up adding the value 2 to the string "a+b=2".  If I do:

echo "a+b=".($a+$b)."<br>";  

it comes out correctly.
 [2003-12-15 04:08 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Indeed, you need to use parenthesis
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC