Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68272 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18634 invoked from network); 21 Jul 2013 01:40:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jul 2013 01:40:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.179 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.212.179 mail-wi0-f179.google.com Received: from [209.85.212.179] ([209.85.212.179:42989] helo=mail-wi0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/D5-17622-9FB3BE15 for ; Sat, 20 Jul 2013 21:40:09 -0400 Received: by mail-wi0-f179.google.com with SMTP id hj3so764561wib.0 for ; Sat, 20 Jul 2013 18:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=RQU7Hvwi9ImlIjTi9UtKm2BcGhDtHqmmxSAzwj0wcRY=; b=kpsMqD6sudu7J5lAmjPG9GpnVjKoyeSIqTQCQRL/T6NnOAYaxieWZB55SGXNlkGFX3 cLOa8IR9WreS3lMB4Uq66yKmz4XQwvXkGlswgnk+S3IY4KHZH2yzBYXi7RJ65Cp11I5U IeGJSTjbwS9oVtGvLv+kUHL9DpRYu/8ZuHsTc//Rbnt35AgWU/F5JGz2Nq6WS/Fw9IE1 QhSvC5LZKCNZ0E46n4TtwT/GMWAUMCFTkNsDH0QKONyCx//awbpzmrbyS1CDWcl3e55A xfzWkwgi/EC9mb04JQFEfmQVKImsVE04mzwAbLmq96I3vZYEfT1/9RzegLAXtj1Ng4mG MBLw== MIME-Version: 1.0 X-Received: by 10.194.9.70 with SMTP id x6mr4811412wja.19.1374370806456; Sat, 20 Jul 2013 18:40:06 -0700 (PDT) Received: by 10.227.207.6 with HTTP; Sat, 20 Jul 2013 18:40:06 -0700 (PDT) In-Reply-To: <51EAF928.3060604@sugarcrm.com> References: <51EA3E36.1090402@sugarcrm.com> <51EAF928.3060604@sugarcrm.com> Date: Sat, 20 Jul 2013 21:40:06 -0400 Message-ID: To: Stas Malyshev Cc: Yasuo Ohgaki , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5d57ceb56b3304e1fba397 Subject: Re: [PHP-DEV] Operator precedence is undefined? From: theanomaly.is@gmail.com (Sherif Ramadan) --047d7b5d57ceb56b3304e1fba397 Content-Type: text/plain; charset=ISO-8859-1 After some digging and a little more thought I find that removing this comment from the example in the docs at www.php.net/language.operators.precedence does indeed cause more harm than good. So I'm definitely wrong in saying that it should be removed. However, I would like to acknowledge the confusion evident in bug 65087 and offer some clarifying language and examples that may assist future users as well as bring some closure to this bug report. As pointed out to me on IRC PHP has exhibited changes in this behavior between PHP < 5.1.0 and PHP >= 5.1.0 where the order of evaluation is not well-defined. The example states that ++$a + $a++ may result in 4 or 5 and that the behavior is undefined. This by itself seems confusing to the user since they always see 4. What's not clear is that this isn't typical everywhere in PHP. For example: $i = 0; $i = $i++; Here $i is always 0, but again the behavior is undefined because in the following code it is not clear what happens: $i = 0; $arr = array(); $arr[$i] = $i++; var_dump($arr); According to the above code produces the following result between PHP 4.3.1 and 5.5.1 array(1) { [0]=> int(0) } Where as the same code produces a very different result between PHP 5.1.0 and above: array(1) { [1]=> int(0) } The same happens with preinc/dec operators as well $i = 0; $arr = array(); $arr[$i] = ++$i; var_dump($arr); PHP < 5.1.0 array(1) { [0]=> int(1) } PHP >= 5.1.0 array(1) { [1]=> int(1) } The problem is I'm not sure where this type of information should be documented. It makes sense to put this on the increment/decrement operators page, but doesn't seem appropriate the operator precedence page. So to make sure we're all in agreement I'm suggesting the following language to be added as a note on the increment/decrement operators page at www.php.net/language.operators.increment with supplement examples provided above to help users get a better understanding of what we mean when we say undefined behavior and add an additional warning box not to rely on this type of behavior. "As noted from the examples above the use of multiple increment/decrement operators in the same expression is considered undefined behavior because the order of evaluation cannot be guaranteed. Using such evaluations may lead to unexpected results." "Warning: Relying on this behavior is discouraged as it may be subject to change and without notice. Results are not typical and are implementation-specific." If anyone feels that could use a little more clarity or can be reworded better let me know. Thanks. --047d7b5d57ceb56b3304e1fba397--