#39338 [Com]: Unexpected answer from if statement dealing with zeros.

From: Date: Thu, 02 Nov 2006 07:15:38 +0000
Subject: #39338 [Com]: Unexpected answer from if statement dealing with zeros.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-104271@lists.php.net to get a copy of this message
 ID:               39338
 Comment by:       judas dot iscariote at gmail dot com
 Reported By:      spideybr at gmail dot com
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Ubuntu 4
 PHP Version:      4.4.4
 New Comment:

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


Use the === operator, this is the expected behaviour.


Previous Comments:
------------------------------------------------------------------------

[2006-11-01 20:39:03] spideybr at gmail dot com

Description:
------------
I've got a "GET variable" called $codArea in my script. Just before the
if statement an echo on the variable would return me "asd" (just to test
it, the normal would be integers btw). Inside the { } in the if
structure, it also echo's "asd".

The problem is, the statement which is returning TRUE (so the script
goes inside de if brackets) is ' $codArea == 0 ' without the single
quotes. Just look in the code and you'll understand. Not a type
conversion misusage, I guess.



Reproduce code:
---------------
//script.php?area=asd on the address bar and on links

$codArea = $_GET['area']; //Creating the "GET variable"

echo $codArea; // returns "asd"

if ($codArea == 0) {
 echo $codArea; // returns "asd"
 echo ($codArea == 0); // returns "1"
}

//All values are printed on the screen without the quotes

Expected result:
----------------
asd

Actual result:
--------------
asd
asd
1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39338&edit=1


Thread (3 messages)

« previous php.bugs (#104271) next »