php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65570 0 equals any string
Submitted: 2013-08-28 09:15 UTC Modified: 2013-08-28 09:18 UTC
From: l dot werner at sprengnetter dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.3 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: l dot werner at sprengnetter dot de
New email:
PHP Version: OS:

 

 [2013-08-28 09:15 UTC] 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) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-28 09:18 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-08-28 09:18 UTC] 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
 [2014-04-04 19:55 UTC] nytyme at gmail dot com
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."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC