Bug #53786 [Opn->Csd]: about "++" or "--"

From: Date: Thu, 10 Feb 2011 12:43:10 +0000
Subject: Bug #53786 [Opn->Csd]: about "++" or "--"
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5948@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53786&edit=1 ID: 53786 Updated by: vrana@php.net Reported by: fx4084 at gmail dot com Summary: about "++" or "--" -Status: Open +Status: Closed Type: Bug Package: Documentation problem Operating System: WIN7 PHP Version: 5.2SVN-2011-01-19 (snap) -Assigned To: +Assigned To: vrana Block user comment: N Private report: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. I've added an example on the Operator Precedence page. Previous Comments: ------------------------------------------------------------------------ [2011-02-10 13:42:47] vrana@php.net Automatic comment from SVN on behalf of vrana Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=308186 Log: Don't mix + and ++ (doc bug #53786) ------------------------------------------------------------------------ [2011-01-19 17:02:30] fx4084 at gmail dot com Thanks for answers! ------------------------------------------------------------------------ [2011-01-19 16:47:07] rasmus@php.net Like Derick said, this is undefined behaviour. Not just in PHP but in most languages. Read this about similar undefined behaviours in C, for example: http://c-faq.com/expr/seqpoints.html Asking for an explanation of undefined behaviour is non-sensical. ------------------------------------------------------------------------ [2011-01-19 14:44:31] fx4084 at gmail dot com replay : derick@php.net example: <?php $a=1; $c=1; $a = $a + $a++ + ++$a; //now $a=6; Why? It is right? How it is interpreted? $c = $c + 0 + $c++ + ++$c; //now $c=5; Why difference between $a and $c? //In C language or JavaScript a=5;c=5; ?> ------------------------------------------------------------------------ [2011-01-19 13:18:22] derick@php.net Mixing ++ and + in the same statement provides undefined behaviour in many languages, including C— depending on optimisation etc. In PHP, this also provides undefined behaviour. I'm marking this as a doc issue, as I can't find anything on http://uk.php.net/manual/en/language.operators.increment.php about this. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=53786 -- Edit this bug report at http://bugs.php.net/bug.php?id=53786&edit=1

« previous php.doc.bugs (#5948) next »