|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-07-06 23:51 UTC] johovich at yande dot ru
Description:
------------
If i use set var inside 'if' statement condition $var = '0' is the same as $var = false. But it is not the same. So 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);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 22 01:00:01 2025 UTC |
and "if($pos = 0)" is always true because = assigns a value while == and === compare a value [harry@srv-rhsoft:/downloads]$ php test.php DO NOT USE A SINGLE = TO COMPARE SOMETHING [harry@srv-rhsoft:/downloads]$ cat test.php <?php if($test = 1) { echo "DO NOT USE A SINGLE = TO COMPARE SOMETHING\n"; } ?>