php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28986 'if' bug
Submitted: 2004-07-01 20:26 UTC Modified: 2004-07-01 20:49 UTC
From: philipp at bind dot ch Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: philipp at bind dot ch
New email:
PHP Version: OS:

 

 [2004-07-01 20:26 UTC] philipp at bind dot ch
Description:
------------
hi there!

I'll past some code here to explain my problem.
I dont know if it is a bug or not bug it looks like one to me!

I had some real ugly problems because of this.
If you have a look at the output of this code you'll see what i mean!
if php commpares 0 with any string the if function tells us that this is true.

I cant believe that the language should be like that so I wrote this bug-report.



Reproduce code:
---------------
$test_char = 'a';
$my_array = array(0, 1, '0', '1', 'a', 'b');
for($i = 0; $i < 6; $i++)
{
        if($my_array[$i] == $test_char)
                echo("php's 'if' tells us that {$my_array[$i]} is the same as {$test_char}\n");
        else
                echo("php's 'if' tells us that {$my_array[$i]} is not the same as {$test_char}\n");
}

Expected result:
----------------
php's 'if' tells us that 0 is not the same as a
php's 'if' tells us that 1 is not the same as a
php's 'if' tells us that 0 is not the same as a
php's 'if' tells us that 1 is not the same as a
php's 'if' tells us that a is the same as a
php's 'if' tells us that b is not the same as a


Actual result:
--------------
php's 'if' tells us that 0 is the same as a
php's 'if' tells us that 1 is not the same as a
php's 'if' tells us that 0 is not the same as a
php's 'if' tells us that 1 is not the same as a
php's 'if' tells us that a is the same as a
php's 'if' tells us that b is not the same as a


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-01 20:49 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is how == works (if either side is an int, the other is also converted to int before comparison).  Use === if you want to take type into account as well as value.

(See also  http://uk.php.net/manual/en/types.comparisons.php and http://uk.php.net/manual/en/language.types.type-juggling.php)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC