Sec Bug->Bug #75114 [Opn]: anomaly when assigning a var in an if-statement

From: Date: Thu, 24 Aug 2017 17:31:22 +0000
Subject: Sec Bug->Bug #75114 [Opn]: anomaly when assigning a var in an if-statement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210796@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75114&edit=1 ID: 75114 Updated by: kalle@php.net Reported by: php at hitchhikers11 dot com Summary: anomaly when assigning a var in an if-statement Status: Open -Type: Security +Type: Bug -Package: *General Issues +Package: Scripting Engine problem PHP Version: Irrelevant Block user comment: N Private report: Y Previous Comments: ------------------------------------------------------------------------ [2017-08-24 13:00:06] php at hitchhikers11 dot com Description: ------------ There is a strange behaveour, when assigning a value in an if-statement (=), instead of equate the variable with a value (==): the value of the variable becomes TRUE respectively 1, this happens only if there is another condition in the if-statement after assigning the variable. Tested with PHP Version 5.6 and 7.? Test script: --------------- $var = "original value"; $var2 = 'some_value'; echo "1: ".$var."<br>"; if($var="value" || false){ echo "2: ".$var."<br>"; } /* && or || */ if("any_true_value"==$var){echo "3: ".$var."<br>";} Expected result: ---------------- 1: original value 2: value Actual result: -------------- 1: original value 2: 1 3: 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75114&edit=1

« previous php.bugs (#210796) next »