Doc #60114 [Opn]: operator increment not working as expected

From: Date: Tue, 25 Oct 2011 18:53:58 +0000
Subject: Doc #60114 [Opn]: operator increment not working as expected
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7352@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60114&edit=1 ID: 60114 User updated by: luuk34 at gmail dot com Reported by: luuk34 at gmail dot com Summary: operator increment not working as expected Status: Open Type: Documentation Problem Package: *General Issues PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: You mean to say the incremantation is done BEFORE the assignment? (in the case $foo=$foo++ ) Previous Comments: ------------------------------------------------------------------------ [2011-10-25 07:14:13] contact at jubianchi dot fr For me, it seems like this is the expected behavior : post-incrementation operator returns the value and the do the incrementation. So the first part of the snippet should print 0 as the second exemple. Only the third par of the snipper should print 1 as the $foo isn't being assigned the return value of the incrementation (we only increment the value). In the manual : $a++ Post-increment Returns $a, then increments $a by one. ------------------------------------------------------------------------ [2011-10-22 17:14:36] luuk34 at gmail dot com The actual result should even be: 111 and not: 011 ------------------------------------------------------------------------ [2011-10-22 16:46:24] luuk34 at gmail dot com Description: ------------ --- From manual page: http://www.php.net/language.operators.increment --- I think there's an error in the second example: $foo=($foo++); it should assign 0 to $foo, and after that increment $foo with 1. But the value of $foo after this line of code is still 0. Test script: --------------- <?php $foo=0; $foo=$foo++; print $foo; $foo=0; $foo=($foo++); print $foo; $foo=0; $foo++; print $foo; ?> Expected result: ---------------- 011 Actual result: -------------- 001 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60114&edit=1

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