php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41470 referance assignment will cause unexpected side effect
Submitted: 2007-05-23 09:19 UTC Modified: 2007-05-24 05:57 UTC
From: xiezhenye at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.2 OS: any
Private report: No CVE-ID: None
 [2007-05-23 09:19 UTC] xiezhenye at gmail dot com
Description:
------------
after a referance assignment, the result of the expression will be an un expected value.

Reproduce code:
---------------
<?php
$a = 1;
$c = ++$a+$a++;
echo $c; 
echo "\n";
$a = 1;
$b = &$a;
$c = ++$a+$a++;
echo $c; 
?>

Expected result:
----------------
4
4

Actual result:
--------------
4
5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-24 05:57 UTC] johannes@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

You shouldn\'t use multiple [in|de]crement operations on the same opeartion. The result of that is undefined.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 20:00:02 2026 UTC