Bug #65062 [Nab]: == operator problem on 0 and string
Edit report at https://bugs.php.net/bug.php?id=65062&edit=1
ID: 65062
User updated by: phoenixsnake at hotmail dot com
Reported by: phoenixsnake at hotmail dot com
Summary: == operator problem on 0 and string
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows 7
PHP Version: 5.3.26
Block user comment: N
Private report: N
New Comment:
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)
Previous Comments:
------------------------------------------------------------------------
[2013-06-19 13:38:31] 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 11:54:24] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65062&edit=1
Thread (3 messages)