Req #71281 [Opn->Sus]: Operators Precedence inside If - Execute increment/decrement before comparison

From: Date: Fri, 04 Aug 2017 23:56:33 +0000
Subject: Req #71281 [Opn->Sus]: Operators Precedence inside If - Execute increment/decrement before comparison
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210500@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71281&edit=1 ID: 71281 Updated by: stas@php.net Reported by: rares_pascut at yahoo dot com Summary: Operators Precedence inside If - Execute increment/decrement before comparison -Status: Open +Status: Suspended Type: Feature/Change Request Package: *General Issues Operating System: all PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: 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 (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here: https://wiki.php.net/rfc/howto If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list (http://php.net/mailing-lists.php) 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. Previous Comments: ------------------------------------------------------------------------ [2016-01-05 11:00:20] rares_pascut at yahoo dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71281&edit=1

« previous php.bugs (#210500) next »