#43935 [Com]: (1 == 'foo') = true
| From: | php at zjs dot name | Date: | Fri, 25 Jan 2008 16:53:32 +0000 |
| Subject: | #43935 [Com]: (1 == 'foo') = true | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121535@lists.php.net to get a copy of this message | ||
ID: 43935
Comment by: php at zjs dot name
Reported By: james dot laver at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: GNU/Linux
PHP Version: 5.2.5
New Comment:
In your description, you use "(1 == 'foo')" and "(true ==
'foo')"
interchangeably. "(1 == 'foo')" isn't the same as "(true ==
'foo')".
Try (using your structure) running:
echo "(true == 'foo') value: " . (true == 'foo') . "<br
/>";
echo "(1 == 'foo') value: " . (1 == 'foo') . "<br />";
echo "(true === 'foo') value: " . (true === 'foo') . "<br
/>";
echo "(1 === 'foo') value: " . (1 === 'foo') . "<br
/>";
Expected result (based on documentation is):
(true == 'foo') value: 1
(1 == 'foo') value:
(true === 'foo') value:
(1 === 'foo') value:
I also created a short test case to ensure that my results matched the
documentation (they did). If you're interested in running it (results
look like http://people.clarkson.edu/~shephezj/temp/comparison_test.php)
it's available at
http://people.clarkson.edu/~shephezj/temp/comparison_test.phps.
(Yes, I know that's a terrible way to code it, but I didn't want to
risk having something interfere with the results).
Previous Comments:
------------------------------------------------------------------------
[2008-01-25 14:11:06] james dot laver at gmail dot com
Description:
------------
(1 == 'foo') returns boolean true
The documentation claims otherwise (see
http://www.php.net/manual/en/types.comparisons.php)
Logically this cannot be true, and it should not be necessary to use
=== to perform this.
Reproduce code:
---------------
echo "value: " . (true == 'foo');
Expected result:
----------------
"value: 0"
Actual result:
--------------
"value: 1"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43935&edit=1