php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54625 string is equals a 0 !?
Submitted: 2011-04-28 17:32 UTC Modified: 2011-04-28 17:45 UTC
From: bernardo at datamex dot com dot br Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: Irrelevant OS: Windows and Freebsd
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: bernardo at datamex dot com dot br
New email:
PHP Version: OS:

 

 [2011-04-28 17:32 UTC] bernardo at datamex dot com dot br
Description:
------------
// tested both in
// in windows 7 - php 5.2.12.12
// in freebsd 7 - php 5.3.3

// because 'e' equals zero, zero is false and false is not equal to 'e'

var_dump(0 == 'e'); // true
var_dump(false == 0); // true
var_dump(false == 'e'); // false
echo '<hr>';

// this means that when we compare int to string will always be equal?

var_dump(0 == "e"); // true
var_dump(0 == "Bernardo"); // true

what is the meaning of this? I think it should not return true.


Test script:
---------------
<?
var_dump(0 == 'e'); // true
?>

Expected result:
----------------
bool(false) 

Actual result:
--------------
bool(true) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-28 17:39 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-04-28 17:39 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

See http://php.net/manual/en/types.comparisons.php
 [2011-04-28 17:45 UTC] rasmus@php.net
Use === to do a strict equality check. == does type juggling
because the Web isn't typed. Everything you get from a Web 
browser is a string so PHP makes sure that 1=='1'. 

In your example, you are comparing variables of different
types, so PHP juggles them to match:

The integer value of string 'e' is zero
The integer value of boolean false is zero
The string value of false is '' which is not 'e'
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC