php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52372 Comparison variable type logic
Submitted: 2010-07-19 00:52 UTC Modified: 2010-07-19 01:54 UTC
From: imagine7xy at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Windows 7
Private report: No CVE-ID: None
 [2010-07-19 00:52 UTC] imagine7xy at gmail dot com
Description:
------------
Pretty self explanatory code, is this how PHP is supposed to behave?

Test script:
---------------
<?php
// outputs string instead of else?
$foo = true;
if ($foo == false) {
	echo "not";
} elseif ($foo == "string") {
	echo "string";
} else {
	echo "else";
}
?>

Expected result:
----------------
output of "else"

Actual result:
--------------
output of "string"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-19 01:54 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-07-19 01:54 UTC] rasmus@php.net
Yup.

if($string) evaluates to true if the string is not empty.  If you want a strict 
typed comparison to true, use if($string===true)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 14:00:01 2025 UTC