#45716 [Opn->Bgs]: Addition and minus operators do not work properly when appended to a string
| From: | derick@php.net | Date: | Tue, 05 Aug 2008 07:42:23 +0000 |
| Subject: | #45716 [Opn->Bgs]: Addition and minus operators do not work properly when appended to a string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127605@lists.php.net to get a copy of this message | ||
ID: 45716
Updated by: derick@php.net
Reported By: pasamio at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux 2.6.5-7.191-smp
PHP Version: 5.2.6
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is because of operator precedence, see:
http://no2.php.net/manual/en/language.operators.php
Previous Comments:
------------------------------------------------------------------------
[2008-08-05 07:39:52] pasamio at gmail dot com
Description:
------------
When using a simple addition or minus operator that is prepended by a
string and concatenated to it will fail to work properly if the string
has a value. When the string is empty (e.g. '' or ' ') it will work
properly. The multiplication and division functions operate
appropriately.
Reproduce code:
---------------
<?php
$x = 10;
$i = 2;
echo "Addition Test\n";
echo 'Test 1: '. $x + $i . "\n";
echo 'Test 2: '. ($x + $i) . "\n";
echo 'Test 3: ';
echo $x + $i . "\n";
echo 'Test 4: ';
echo ''. $x + $i ."\n";
echo "\n";
echo "Subtraction Test\n";
echo 'Test 1: '. $x - $i . "\n";
echo 'Test 2: '. ($x - $i) . "\n";
echo 'Test 3: ';
echo $x - $i . "\n";
echo 'Test 4: ';
echo 'x'. $x - $i ."\n";
echo "\n";
Expected result:
----------------
moffats@dev1:~/public_html/testing> php bug-minus.php
Addition Test
Test 1: 12
Test 2: 12
Test 3: 12
Test 4: 12
Subtraction Test
Test 1: 8
Test 2: 8
Test 3: 8
Test 4: 8
Actual result:
--------------
moffats@dev1:~/public_html/testing> php bug-minus.php
Addition Test
2
Test 2: 12
Test 3: 12
Test 4: 12
Subtraction Test
-2
Test 2: 8
Test 3: 8
Test 4: 8
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45716&edit=1