php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40860 increment operator works different than plus operator
Submitted: 2007-03-20 07:30 UTC Modified: 2007-03-20 10:02 UTC
From: tjerk dot meesters at muvee dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.1 OS: Linux 2.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tjerk dot meesters at muvee dot com
New email:
PHP Version: OS:

 

 [2007-03-20 07:30 UTC] tjerk dot meesters at muvee dot com
Description:
------------
Applying the increment operator (++) on a variable (containing a number) ending with a newline character doesn't change the variable.

However, applying += 1 to the same variable does result in the right behaviour.

Reproduce code:
---------------
function showsucc($x)
{
  // using increment operator
  $tmp = $x; $tmp++;
  echo "successor of $x = ",$tmp,"\n";
  // using plus operator
  $tmp = $x; $tmp += 1;
  echo "result of $x + 1 = ",$tmp,"\n";
}

showsucc("123\n");
showsucc("123");


Expected result:
----------------
successor of 123
 = 124
result of 123
 + 1 = 124
successor of 123 = 124
result of 123 +1 = 124

Actual result:
--------------
successor of 123
 = 123 <---- difference is here

result of 123
 + 1 = 124
successor of 123 = 124
result of 123 + 1 = 124


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-20 10:02 UTC] tony2001@php.net
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


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 11:00:02 2025 UTC