php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53584 Asterisk character equals 0
Submitted: 2010-12-20 21:45 UTC Modified: 2010-12-20 22:36 UTC
From: andy dot mezey at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andy dot mezey at gmail dot com
New email:
PHP Version: OS:

 

 [2010-12-20 21:45 UTC] andy dot mezey at gmail dot com
Description:
------------
Using PHP Version 5.3.2-1ubuntu4.5.  When a variable holds the value "*" and when being compared against the values 0 or "0" using the equal operator, true is always returned.  I did look here: http://php.net/manual/en/language.types.type-juggling.php and I do not see a reason for this behavior.  The Identical operator does however return false which is what you would expect.

Test script:
---------------
$var1 = "*";

if( $var1 == 0 )
{
  echo "ok";
}

switch( $var1 )
{
  case 0 :
   echo "ok";
   break;
}

$var2 = "\*";

if( $var2 == 0 )
{
  echo "ok";
}

switch( $var2 )
{
  case 0 :
   echo "ok";
   break;
}

Expected result:
----------------
Should return false.

Actual result:
--------------
Returns true;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 22:20 UTC] cataphract@php.net
-Status: Open +Status: Bogus -Package: Output Control +Package: Scripting Engine problem
 [2010-12-20 22:20 UTC] cataphract@php.net
Everything in your test script is expected behavior. "*" == "0" being true is not, but that claim isn't tested in the test script and I can't reproduce, which leads me to conclude it was a mistake on the your part.

php -r 'var_dump("*" == "0");'
bool(false)
 [2010-12-20 22:30 UTC] andy dot mezey at gmail dot com
Are you saying when running the examples provided nothing was printed to the screen; that the statements returned false?  I just tried my examples on another server running PHP Version 5.2.13 and received the same results as before.  When I execute the code var_dump( "*" == 0 );, bool(true) is returned.
 [2010-12-20 22:36 UTC] rasmus@php.net
"*" == 0 
and
"*" == "0"
are very different cases.

In the first you are comparing a string to an integer, so the string will be 
cast to an integer and the integer value of "*" is 0 so that will be equal.

In the second you are comparing strings, so "*" and "0" will not be equal.
 [2010-12-20 23:04 UTC] andy dot mezey at gmail dot com
Yes, I see it now. (http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion).  I'm very sorry to have wasted each of your time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC