php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20726 'foo'==0 cast on comparison
Submitted: 2002-11-29 08:39 UTC Modified: 2004-05-22 11:20 UTC
From: wb at sapo dot pt Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.2.3 OS:
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: wb at sapo dot pt
New email:
PHP Version: OS:

 

 [2002-11-29 08:39 UTC] wb at sapo dot pt
yesterday i submitted an 'foo'==0 bug (id=20708) in the Scripting Engine problem Category, well i understand that was stupid and my bug went bogus just as ahundret other submitted 'foo'==0 bugs i later found in the database.

but i think it is an issue.

the manual states:

Example: $a == $b 
Name: Equal 
Result: TRUE if $a is equal to $b
 
this is not specific enough for a language where 'foo'==0 evaluates TRUE.

when i write 'foo'==0 i do *not* want to know if they are same type

i want to know one of those:
'foo'==(string)0 *or* (int)'foo'==0

obviously, only one of those can happen. if you want the other thing to happen, you must cast explicitly. the manual doesn't state which one happens implicitly.

automatic type casting is great for coding, but one can't just let it happen, one must know exactly what it does. 

i hope you understand that a nonempty string to be the same as a zero integer messes with the brain of any php newbie used to fixed type languages if you don't explain to him why.

the manual shouldn?t just state that 'foo' equals to 0, because for this to happen php seems to use a cast precedence for comparison operations - whatever it is, the manual should explain it.

PS:
if you bogus me again i wont insist.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-29 08:44 UTC] derick@php.net
IMO it can be documented better indeed, for example at this page: http://www.php.net/manual/en/language.operators.comparison.php

Derick
 [2002-12-01 07:12 UTC] wb at sapo dot pt
refiling into (documentation) feature request for the following reason:

the problem i pointed out was a missconception of mine, not a wrong info in the docs, thus not a 'documentation problem'

given that, i should have submitted information about it as a feature request for new information in the manual, instead of blaming the manual for my missconception. i wish to appologize for that (btw it is one of the best reference manuals i've seen).

last, since no other php newbie has given me authority for speaking on his behalf, i must refrase that statement of mine: the issue messed with my brain. it made it stop working for a while...
 [2002-12-01 07:14 UTC] derick@php.net
We need to keep it in the Documentation category, otherwise the doc-ppl won't see it.

Derick
 [2003-02-25 18:14 UTC] info at lukki dot de
I just had 2 different strings give me a true on comparison:

"11111111117301147" == "11111111117301148" was true!

Now I replaced the == with strcmp and it works fine...but this seems to be a bug.

Here is the code:
if($vergleich == $ids[$j]) $error .= "==doppelte..:";

with $vergleich = "11111111117301147" and
$ids[$j] = "11111111117301148"
 [2004-05-22 11:20 UTC] nlopess@php.net
Duplicate of #23110
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 23 22:01:25 2020 UTC