Bug #65570 [Com]: 0 equals any string

From: Date: Fri, 04 Apr 2014 19:55:26 +0000
Subject: Bug #65570 [Com]: 0 equals any string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185091@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65570&edit=1 ID: 65570 Comment by: nytyme at gmail dot com Reported by: l dot werner at sprengnetter dot de Summary: 0 equals any string Status: Not a bug Type: Bug Package: *General Issues Operating System: Linux PHP Version: 5.5.3 Block user comment: N Private report: N New Comment: No, this is in fact a bug. It is completely unexpected and inappropriate behavior. When someone says when $var == "SOMESTRING", they literally mean that $var MUST "SOMESTRING", not "$var should be SOMESTRING, but you know if you don't feel like making sure, just do it anyways. It's all good bro." Previous Comments: ------------------------------------------------------------------------ [2013-08-28 09:18:11] nikic@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. http://php.net/manual/en/language.operators.comparison.php ------------------------------------------------------------------------ [2013-08-28 09:15:38] l dot werner at sprengnetter dot de Description: ------------ When matching any string against 0 with == or != PHP will say they match. This is in my eyes absolutely wrong because testing against other types will not result in this behavior. Test script: --------------- <?php echo "null != 'string' -> "; var_dump(null != 'string'); echo "<br />"; echo "false != 'string' -> "; var_dump(false != 'string'); echo "<br />"; echo "0 != 'string' -> "; var_dump(0 != 'string'); echo "<br />"; echo "1 != 'string' -> "; var_dump(1 != 'string'); Expected result: ---------------- null != 'string' -> bool(true) false != 'string' -> bool(true) 0 != 'string' -> bool(true) 1 != 'string' -> bool(true) Actual result: -------------- null != 'string' -> bool(true) false != 'string' -> bool(true) 0 != 'string' -> bool(false) 1 != 'string' -> bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65570&edit=1

« previous php.bugs (#185091) next »