Bug #60672 [Com]: ELSEIF/ELSE IF doesn't work
Edit report at https://bugs.php.net/bug.php?id=60672&edit=1
ID: 60672
Comment by: anon at anon dot anon
Reported by: danillo dot paiva dot toledo at gmail dot com
Summary: ELSEIF/ELSE IF doesn't work
Status: Open
Type: Bug
Package: Variables related
Operating System: Windows XP
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-01-06 16:14:32] 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:11:19] 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.".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60672&edit=1
Thread (5 messages)