php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43935 (1 == 'foo') = true
Submitted: 2008-01-25 14:11 UTC Modified: 2008-01-25 17:30 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: james dot laver at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: james dot laver at gmail dot com
New email:
PHP Version: OS:

 

 [2008-01-25 14:11 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-25 16:53 UTC] php at zjs dot name
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).
 [2008-01-25 17:22 UTC] james dot laver at gmail dot com
That's not the result I get here. Have tried this both with home compiled PHP and with rPath's binaries

[james@james ~]$ php -v
PHP 5.2.5 (cli) (built: Jan 25 2008 13:02:08) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
 [2008-01-25 17:30 UTC] james dot laver at gmail dot com
Sorry, i hit submit before I was finished and then I was wrong anyway.

Human error.

<?php
echo "php == true ". (('php'==true)?'true':'false') . "\n";
echo "1 == php " . (('php'==1)?'true':'false');
?>
php == true true
1 == php false

Closing as bogus, sorry about that
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 05:01:34 2025 UTC