php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12453 comparing 0==null is true?
Submitted: 2001-07-28 22:54 UTC Modified: 2001-08-01 03:59 UTC
From: btanner at home dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: Win2k
Private report: No CVE-ID: None
 [2001-07-28 22:54 UTC] btanner at home dot com
If you compare the integer(0) to the string "null", PHP thinks they are the same.

Am I hopped up on goofballs, or whats up here?

$MyVar=0;
if($MyVar=="null")
	print("apparently $MyVar is equal to \"null\"");
else
	print("its not null, its $MyValue");


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-31 08:40 UTC] andy@php.net
i thought that any integer =0 was also equal to any string...

for example (in your script):

$MyVar=0;
if ($MyVar=="blahblahblahblah")
echo "yes";
else
echo "no";


will echo "yes"

I don't know if this is supposed to happen, but it does.
If you set the $MyVar=1, the script prints no.

Can anybody else verify if this is supposed to happen, or
if this is actually a bug?

 [2001-08-01 03:59 UTC] joey@php.net
This is not a bug.
This is correct behavior.

For future reference, please try the following before reporting a bug:

http://www.php.net/bugs-dos-and-donts.php


For more info:
http://php.net/manual/en/language.operators.comparison.php
http://php.net/manual/en/language.types.string.php#language.types.string.conversion
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 07:01:32 2024 UTC