#26624 [Opn->Bgs]: cannot get the right value when i use + operator
| From: | derick@php.net | Date: | Mon, 15 Dec 2003 09:08:13 +0000 |
| Subject: | #26624 [Opn->Bgs]: cannot get the right value when i use + operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-52072@lists.php.net to get a copy of this message | ||
ID: 26624
Updated by: derick@php.net
Reported By: mlsx at cie dot xtu dot edu dot cn
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: windows server 2003
PHP Version: 4.3.3
New Comment:
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 http://www.php.net/support.php 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
Previous Comments:
------------------------------------------------------------------------
[2003-12-15 03:56:03] 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 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