Edit report at https://bugs.php.net/bug.php?id=54547&edit=1

 ID:                 54547
 Updated by:         paj...@php.net
 Reported by:        peter dot ritt at gmx dot net
 Summary:            wrong equality of string numbers
 Status:             Verified
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   linux
 PHP Version:        5.3.6
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

@Jeff at bobmail dot info

that's what === is for (real comparisons without casting).


Previous Comments:
------------------------------------------------------------------------
[2012-04-12 13:51:22] jabakobob at gmail dot com

The conversion to a number is necessary because programmers don't differentiate 
between strings and numbers in PHP. Consider the following code:

if ($_GET["a"] == $_GET["b"]) echo "a is same as b!";

The result will be the same if the query string is ?a=1&b=1 or ?a=1&b=1.0 or ?
a=01&b=1 because PHP is loosely typed.

Internally $_GET["a"] and $_GET["b"] are both strings, but we can't do a string 
comparison. If you want a string comparison, use strcmp.

------------------------------------------------------------------------
[2012-04-12 13:31:42] Jeff at bobmail dot info

I'm confused as to why there is even a conversation around "should we fix this".

The data objects are strings. Sure, PHP is "loosely typed" but shouldn't it do 
the comparison you tell it to do first before attempting anything else?

I agree with the previous suggestion: make it a real string comparison and drop 
the type casting.

------------------------------------------------------------------------
[2012-04-12 06:39:31] paj...@php.net

@a at hotmail dot com

This is not a support channel, if you need further support for the base ideas 
about the loosely type nature of PHP, please ask them on one the numerous 
channels.

------------------------------------------------------------------------
[2012-04-12 06:39:30] paj...@php.net

@a at hotmail dot com

This is not a support channel, if you need further support for the base ideas 
about the loosely type nature of PHP, please ask them on one the numerous 
channels.

------------------------------------------------------------------------
[2012-04-12 06:39:30] paj...@php.net

@a at hotmail dot com

This is not a support channel, if you need further support for the base ideas 
about the loosely type nature of PHP, please ask them on one the numerous 
channels.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=54547


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54547&edit=1

Reply via email to