|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65087 There is a confusing comment in example
Submitted: 2013-06-21 15:02 UTC Modified: 2020-08-14 08:54 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: truenrush at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.5.0 OS: Any
Private report: No CVE-ID: None
 [2013-06-21 15:02 UTC] truenrush at gmail dot com
I would like to report about "Example #1 Associativity" on the following docs 
page, because it is very confusing:

1. According to operators precedence table, "++" operator precedence is MUCH MORE 
higher then "+" one. As i understand, exactly pre-increment, because post-
increment is always executed last one (table with precedence order is not correct, 
eh? do we need to separate pre-increments and post-increments there?)

2. According to 
page, there should be following scenario for your example:

- $a variable is pre-incremented (becomes $a = 2)
- sum is calculated for $a + $a variables (4 number will be printed by echo)
- $a variable is post-incremented (becomes $a = 3)

Test script:
// mixing ++ and + produces undefined behavior - WTF? result should always be 4
$a = 1;
echo ++$a + $a++; // may print 4 or 5


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-20 01:13 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: yohgaki
 [2013-07-20 01:13 UTC]
Checking if doc is true or not.
 [2013-07-20 03:39 UTC]
-Status: Assigned +Status: Closed
 [2013-07-20 03:39 UTC]
Fixed wrong documentation.
Doc will be updated in a few days.
Thank you.
 [2013-07-20 05:39 UTC]
-Status: Closed +Status: Re-Opened -Assigned To: yohgaki +Assigned To:
 [2013-07-20 05:39 UTC]
Reopening, since the commit was reverted and it's being discussed on Internals.
 [2020-08-14 08:54 UTC]
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: cmb
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 20 23:01:27 2024 UTC