#40755 [NEW]: Increment/Decrement operator calculation oddity

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40755 [NEW]: Increment/Decrement operator calculation oddity

    From: henson dot garth at gmail dot com
    Operating system: Linux
    PHP version: 5.2.1
    PHP Bug Type: Math related
    Bug description: Increment/Decrement operator calculation oddity

    Description:
    ------------
    The increment/decrement operators seem to calculate out of order compared
    to other languages and even previous versions of PHP. I compared this
    report numerous times against a 4.3.11 install that I am running to verify
    the inconsistency. In the case of PHP 5.2.x, the increment operator seems
    to be processed in an inappropriate order to the rest of the statement. In
    4.3.11, everything is presented just as expected (as my Expected results
    display below).

    Reproduce code:
    ---------------
    $a = array(); // Begin Test 1
    $b = 0;
    $a[$b++] = $b;
    var_dump($a);

    $a = array(); // Begin Test 2
    $b = 0;
    $a[$b] = $b++;
    var_dump($a);

    $a = array(); // Begin Test 3
    $b = 10;
    $a[$b--] = $b;
    var_dump($a);

    $a = array(); // Begin Test 4
    $b = 10;
    $a[$b] = $b--;
    var_dump($a);

    Expected result:
    ----------------
    array(1){[0] => int(1)}
    array(1){[0] => int(0)}
    array(1){[10] => int(9)}
    array(1){[10] => int(10)}

    Actual result:
    --------------
    array(1){[0] => int(1)}
    array(1){[1] => int(0)}
    array(1){[10] => int(9)}
    array(1){[9] => int(10)}

    --
    Edit bug report at [url]http://bugs.php.net/?id=40755&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40755&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40755&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40755&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40755&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40755&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40755&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40755&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40755&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40755&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40755&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40755&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40755&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40755&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40755&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40755&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40755&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40755&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40755&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40755&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40755&r=mysqlcfg[/url]
    henson dot garth at gmail dot com Guest

  2. Similar Questions and Discussions

    1. #39609 [NEW]: increment/decrement inconsistency
      From: arpad@php.net Operating system: PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem Bug description: ...
    2. Date oddity in Acrobat, default page size oddity
      Got two things driving me nuts. One, when I go to Save As a file, the file dats come up in the form like this: Saturday, July -2147483642, 41221,...
    3. Calculation based on calculation
      I'm new to Acrobat 5.05 and Javascript... I have a simple issue/question: There are 3 columns, QUANTITY, EACHES COST, LINE TOTAL As the...
    4. #25674 [Opn->Bgs]: increment/decrement inconsistency and error
      ID: 25674 Updated by: sniper@php.net Reported By: lew at mailduct dot com -Status: Open +Status: ...
    5. #25674 [NEW]: increment/decrement inconsistency and error
      From: lew at mailduct dot com Operating system: FreeBSD 4.8-REL PHP version: 4.3.3 PHP Bug Type: Math related Bug...
  3. #2

    Default #40755 [Opn->Bgs]: Increment/Decrement operator calculation oddity

    ID: 40755
    Updated by: [email]derick@php.net[/email]
    Reported By: henson dot garth at gmail dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Math related
    Operating System: Linux
    PHP Version: 5.2.1
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the documentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    Using and modifying the same variable when using post/pre-
    decrement/increment is undefined (and not only in PHP).


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-08 01:43:13] henson dot garth at gmail dot com

    Description:
    ------------
    The increment/decrement operators seem to calculate out of order
    compared to other languages and even previous versions of PHP. I
    compared this report numerous times against a 4.3.11 install that I am
    running to verify the inconsistency. In the case of PHP 5.2.x, the
    increment operator seems to be processed in an inappropriate order to
    the rest of the statement. In 4.3.11, everything is presented just as
    expected (as my Expected results display below).

    Reproduce code:
    ---------------
    $a = array(); // Begin Test 1
    $b = 0;
    $a[$b++] = $b;
    var_dump($a);

    $a = array(); // Begin Test 2
    $b = 0;
    $a[$b] = $b++;
    var_dump($a);

    $a = array(); // Begin Test 3
    $b = 10;
    $a[$b--] = $b;
    var_dump($a);

    $a = array(); // Begin Test 4
    $b = 10;
    $a[$b] = $b--;
    var_dump($a);

    Expected result:
    ----------------
    array(1){[0] => int(1)}
    array(1){[0] => int(0)}
    array(1){[10] => int(9)}
    array(1){[10] => int(10)}

    Actual result:
    --------------
    array(1){[0] => int(1)}
    array(1){[1] => int(0)}
    array(1){[10] => int(9)}
    array(1){[9] => int(10)}


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40755&edit=1[/url]
    derick@php.net Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139