Bug #74871 [NEW]: if statement behavior

From: Date: Thu, 06 Jul 2017 23:51:24 +0000
Subject: Bug #74871 [NEW]: if statement behavior
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209873@lists.php.net to get a copy of this message
From: johovich at yande dot ru Operating system: Linux version 2.6.32-531.23.3.lv PHP version: 7.1.7 Package: *General Issues Bug Type: Bug Bug description:if statement behavior 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 bug report at https://bugs.php.net/bug.php?id=74871&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74871&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74871&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74871&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74871&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74871&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74871&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74871&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74871&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74871&r=support Expected behavior: https://bugs.php.net/fix.php?id=74871&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74871&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74871&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74871&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74871&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74871&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74871&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74871&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74871&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74871&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74871&r=mysqlcfg

« previous php.bugs (#209873) next »