Bug #74871 [Com]: if statement behavior

From: Date: Fri, 07 Jul 2017 00:01:33 +0000
Subject: Bug #74871 [Com]: if statement behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209874@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74871&edit=1 ID: 74871 Comment by: rtheunissen@php.net Reported by: johovich at yande dot ru Summary: if statement behavior Status: Open Type: Bug Package: *General Issues Operating System: Linux version 2.6.32-531.23.3.lv PHP Version: 7.1.7 Block user comment: N Private report: N New Comment: This is not a bug. if ($condition) is the same as if ($condition == true), so in the second part of your test script if you changed the strict !== to !=, you would get the same results. So you're effectively saying if (($pos = 0) == true) which will drop to the else. Previous Comments: ------------------------------------------------------------------------ [2017-07-06 23:51:22] 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); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74871&edit=1

« previous php.bugs (#209874) next »