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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 09:01:31 2024 UTC