php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25674 increment/decrement inconsistency and error
Submitted: 2003-09-26 15:38 UTC Modified: 2003-09-27 07:47 UTC
From: lew at mailduct dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.3 OS: FreeBSD 4.8-REL
Private report: No CVE-ID: None
 [2003-09-26 15:38 UTC] lew at mailduct dot com
Description:
------------
There is a gross inconsistency between how the increment and decrement operators function.  If you increment an empty variable, the operations works correctly.  However, if you *decrement* an empty variable, the operation leaves it unchanged!  See for yourself, with my clear example...

Reproduce code:
---------------
<?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
?>


Expected result:
----------------
#
#  Expected:
#    pos = 3    ppp = 3
#    neg = -3   nnn = -3


Actual result:
--------------
#
#  Actual:
#    pos = 3    ppp = 3
#    neg =      nnn = -3

(note that $neg-- fails!)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-27 07:47 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

See bug #20548

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC