|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71281 Operators Precedence inside If - Execute increment/decrement before comparison
Submitted: 2016-01-05 11:00 UTC Modified: 2017-08-04 23:56 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rares_pascut at yahoo dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: Next Minor Version OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rares_pascut at yahoo dot com
New email:
PHP Version: OS:


 [2016-01-05 11:00 UTC] rares_pascut at yahoo dot com
In Java ,C# , C, C++ the increment/decrement is called before the comparison inside an if statement. In PHP the post increment/decrement is executed after the comparison.

This should be changed. Because the operators should be called before the comparison. 

The pre and post increment/decrement should both be executed before the comparison inside an if statement.

Test script:
PHP code:
function calc() {
        $i = 5;
        if ($i == $i++)
            echo("1: i is equal to i++");
        if ($i++ == $i)
            echo("2: i++ is equal to i");
        if ($i == ++$i)
            echo("3: i is equal to ++i");
        if (++$i == $i)
            echo("4: ++i is equal to i");

C# code:

private static void Main(string[] args)
    int i = 5;
    if (i == i++)
        Console.WriteLine("1: i is equal to i++");
    if (i++ == i)
        Console.WriteLine("2: i++ is equal to i");
    if (i == ++i)
        Console.WriteLine("3: i is equal to ++i");
    if (++i == i)
        Console.WriteLine("4: ++i is equal to i");

Expected result:
1: i is equal to i++
4: ++i is equal to i

Actual result:
3: i is equal to ++i
4: ++i is equal to i


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-01 21:00 UTC]
-Package: operator +Package: *General Issues
 [2017-08-04 23:56 UTC]
-Status: Open +Status: Suspended
 [2017-08-04 23:56 UTC]
Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list ( as an RFC. Please read the guide about creating RFCs here:
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list ( and/or solicit help from one of the experienced developers. 

Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jun 18 14:01:24 2021 UTC