php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65062 == operator problem on 0 and string
Submitted: 2013-06-19 11:54 UTC Modified: 2013-06-19 14:54 UTC
From: phoenixsnake at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.26 OS: Windows 7
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: phoenixsnake at hotmail dot com
New email:
PHP Version: OS:

 

 [2013-06-19 11:54 UTC] phoenixsnake at hotmail dot com
Description:
------------
problem occur when compare string with 0

Test script:
---------------
var_dump( 0 == "something" );

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

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-19 13:38 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-06-19 13:38 UTC] ab@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

Please read the docs http://php.net/manual/en/language.types.type-juggling.php
 [2013-06-19 14:54 UTC] phoenixsnake at hotmail dot com
Thank you for your reply, 
I will keep in mind that String without leading number will convert to 0 when compare to number with operator ==.

No offend. Just wonder.
I think type conversion is make sense when use with +, -, *, / operator.
Shouldn't we convert number to string before compare ( == ) between number and String ?

for example

var_dump( 10 == $_POST[ 'input' ] ); #example, user's input some data

var_dump( 10 == "10" ); #bool(true)

Those statements look strange.
var_dump( 10 == "10,15" ); #bool(true)
var_dump( 10 == "10 Little Piggies" ); #bool(true)
var_dump( "something" == 0 ); #bool(true)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 21:01:27 2025 UTC