php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60672 ELSEIF/ELSE IF doesn't work
Submitted: 2012-01-06 16:11 UTC Modified: 2012-01-09 15:13 UTC
From: danillo dot paiva dot toledo at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: Irrelevant OS: Windows XP
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: danillo dot paiva dot toledo at gmail dot com
New email:
PHP Version: OS:

 

 [2012-01-06 16:11 UTC] danillo dot paiva dot toledo at gmail dot com
Description:
------------
$x = 0;
$y = "some_string";

if( $x == 2 ) {
	echo "X = 2.<br/>";
	echo "Inner first IF";
} elseif ( $x == $y ) {
	echo "We are at the elseif condition.";
} else {
	echo "I don't know what's X value.";
}

Test script:
---------------
1st - That's my first time using bug report on php.net.
2nd - I'm brazilia(sorry my english).
3rd - I don't know I'm using the correct channel to report this.

I used WAMPServer2.1 to discover this bug.
The current PHP version used on used WAMPServer2.1 is 5.3.5.

This prints "We are at the elseif condition.".
The same happens if the $y value is false.

Expected result:
----------------
Expected result would be: "I don't know what's X value.".

Actual result:
--------------
Actual result would be: "I don't know what's X value.".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-06 16:14 UTC] danillo dot paiva dot toledo at gmail dot com
$x = 0;
$y = "some_string";

if( $x == 2 ) {
	echo "X = 2.<br/>";
	echo "Inner first IF";
} elseif ( $x == $y ) {
	echo "We are at the elseif condition.";
} else {
	echo "I don't know what's X value.";
}


1st - That's my first time using bug report on php.net.
2nd - I'm brazilia(sorry my english).
3rd - I don't know I'm using the correct channel to report this.

I used WAMPServer2.1 to discover this bug.
The current PHP version used on used WAMPServer2.1 is 5.3.5.

This prints "We are at the elseif condition.".
The same happens if the $y value is false.
 [2012-01-06 16:22 UTC] anon at anon dot anon
This occurs because 0 == "some_string" is true, and 0 == false is true. See:
http://php.net/manual/en/types.comparisons.php
Use === instead of == (and !== instead of !=) to stop type conversion in comparisons.
 [2012-01-06 22:03 UTC] felipe@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


 [2012-01-06 22:03 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2012-01-09 15:13 UTC] danillo dot paiva dot toledo at gmail dot com
I used the === instead of == and it worked as expected.

But I wanna know, why 0 == "some_string" returns true?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 02:01:26 2025 UTC