note 36224 added to language.operators.increment

From: Date: Wed, 01 Oct 2003 18:12:28 +0000
Subject: note 36224 added to language.operators.increment
Groups: php.notes 
Request: Send a blank email to php-notes+get-57551@lists.php.net to get a copy of this message
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! ---- Manual Page -- http://www.php.net/manual/en/language.operators.increment.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36224 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36224&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36224&report=yes

« previous php.notes (#57551) next »