#26624 [Com]: cannot get the right value when i use + operator
| From: | benjcarson at digitaljunkies dot ca | Date: | Mon, 15 Dec 2003 08:56:03 +0000 |
| Subject: | #26624 [Com]: cannot get the right value when i use + operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-52071@lists.php.net to get a copy of this message | ||
ID: 26624
Comment by: benjcarson at digitaljunkies dot ca
Reported By: mlsx at cie dot xtu dot edu dot cn
Status: Open
Bug Type: Math related
Operating System: windows server 2003
PHP Version: 4.3.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2003-12-15 02:45:01] mlsx at cie dot xtu dot edu dot cn
Description:
------------
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:
---------------
<?php
$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:
----------------
2
-2
a*b=16
a/b=4
a%c=2
a++ is 8
Actual result:
--------------
a+b=10
a-b=6
a*b=16
a/b=4
a%c=2
a++ is 8
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26624&edit=1