php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39531 soft evaluation between integers and strings
Submitted: 2006-11-16 11:08 UTC Modified: 2006-11-20 00:04 UTC
From: jakobsg at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.4.4 OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jakobsg at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-16 11:08 UTC] jakobsg at gmail dot com
Description:
------------
This is pretty straight forward.
The soft evaluation (==) feature in php can be nice, personally I never use it, but I acknowledge that it can be useful in some situations.
The result of the following evaluation however is not acceptable by any means (even in soft evaluation):

0 == '0'  (true, and acceptable)
0 == 'o'  (true, really!!!)

0 == 'o' are equal ... Common - this can only lead to errors.

Best regards Jakob Simon-Gaarde

Reproduce code:
---------------
var_export(0=='o');

Expected result:
----------------
false

Actual result:
--------------
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-16 11:15 UTC] tony2001@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


 [2006-11-16 21:07 UTC] jakobsg at gmail dot com
Is there some where in particular I should look?

It's not here:
http://www.php.net/manual/da/types.comparisons.php
 [2006-11-17 10:49 UTC] mgf@php.net
Er -- yes it is. Table O-2, to be specific.
 [2006-11-17 11:56 UTC] jakobsg at gmail dot com
OK, I think you missed the point. It's not the stringified zero ("0") I'm talking about, it's the letter "o" that evaluates true when compared with zero. The letter "o" is no where en the O-2 table. Sorry if we have been talking about apples and bananas :-)
 [2006-11-20 00:04 UTC] mgf@php.net
No, I haven't missed the point at all -- you have.  In that table, the last row and last column have the heading "php" which is intended to represent *all* strings except the 3 explicitly mentioned elsewhere -- this would include the string "o".

(This conversion of non-numeric strings to zero is also noted at http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC