note 36224 rejected from language.operators.increment by pollita
| From: | pollita@php.net | Date: | Wed, 01 Oct 2003 18:31:35 +0000 |
| Subject: | note 36224 rejected from language.operators.increment by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57553@lists.php.net to get a copy of this message | ||
Note Submitter: lew@mailduct.com
----
WARNING: There is a GROSS inconsistency between the increment and decrement operators. DECREMENT
will FAIL under certain circumstances. The PHP team has decided not to fix this problem. See Bug
Report for more info:
http://bugs.php.net/bug.php?id=20548</a>
Here is example code (and output):
<?php
// Increment some blank/empty variables...
$pos++; $pos++; $pos++;
$neg--; $neg--; $neg--;
// Show them to us now...
print( "pos = $pos\n" );
print( "neg = $neg\n" );
// Now do it another way (forced typecast)...
$ppp += 1; $ppp += 1; $ppp += 1;
$nnn -= 1; $nnn -= 1; $nnn -= 1;
// Show them to us now...
print( "ppp = $ppp\n" );
print( "nnn = $nnn\n" );
#
# Expected:
# pos = 3 ppp = 3
# neg = -3 nnn = -3
#
# Actual:
# pos = 3 ppp = 3
# neg = nnn = -3
?>
Unlike the increment operator, which works fine, if you want to use the DECREMENT operator you
should make sure your variable is first initialized to zero or any valid number!