php.net |  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
Votes:1
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
Description:
------------
I would like to report about "Example #1 Associativity" on the following docs 
page, because it is very confusing:
http://www.php.net/manual/en/language.operators.precedence.php

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 http://www.php.net/manual/en/language.operators.increment.php 
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


Patches

Pull Requests

History

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