|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-04-01 21:00 UTC] tpunt@php.net
-Package: operator
+Package: *General Issues
[2017-08-04 23:56 UTC] stas@php.net
-Status: Open
+Status: Suspended
[2017-08-04 23:56 UTC] stas@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 13:00:01 2025 UTC |
Description: ------------ 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