php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31458 0 == '%' is true?
Submitted: 2005-01-09 21:51 UTC Modified: 2005-01-09 22:07 UTC
From: falk at brockerhoff dot org Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.10 OS: FreeBSD 5.3
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: falk at brockerhoff dot org
New email:
PHP Version: OS:

 

 [2005-01-09 21:51 UTC] falk at brockerhoff dot org
Description:
------------
I got a strange problem while comparing a numeric while with the string "%". Using the numeric value 0 and the string "%" in an if-statement results with true!?



Reproduce code:
---------------
$foo = '%';
$bar = 0;

if ($foo == $var)
{
  echo "what the hell is going on?!\n";
}

$foo = '%';
$bar = '0';

if ($foo == $var)
{
  echo "what the hell is going on?!\n";
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-09 21:58 UTC] tony2001@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

Use === to compare variables of different types and read the documentation about type juggling.
 [2005-01-09 22:00 UTC] falk at brockerhoff dot org
Oh, it's not a bug, it's a feature:

http://www.php.net/manual/en/language.operators.comparison.php
 [2005-01-09 22:07 UTC] johannes@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

Quoting 
http://de2.php.net/manual/en/language.operators.comparison.php 
 
\"If you compare an integer with a string, the string is 
converted to a number. If you compare two numerical 
strings, they are compared as integers. These rules also 
apply to the switch statement.\" 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC