note 121331 deleted from control-structures.if by cmb
| From: | cmb@php.net | Date: | Fri, 02 Oct 2020 12:22:44 +0000 |
| Subject: | note 121331 deleted from control-structures.if by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215510@lists.php.net to get a copy of this message | ||
Note Submitter: johovich at yandex dot ru
----
'IF' STATEMENT WRONG BEHAVIOR
If assign var to function that returns 0 as integer or 0 as string 'if' statement
condition works as false.
Test script:
---------------
//In this script you can see, that set var value to 0 is equal to boolean false
//applied to if statement. There is no diff between integer 0 or string '0'
if($pos = 0){
$pos++;
} else {
$pos = 0;
}
var_dump($pos);
//$pos is not boolean false, so it should do if condition true, but it's not
//to make this work well i use this
$pos = 0;
if($pos !== false){
$pos++;
} else {
$pos = 0;
}
var_dump($pos);