Page 1 of 1

Variable recognition

Posted: Thu Apr 28, 2005 11:35 am
by mjseaden
Hi

I can't work out what is causing this strange problem with PHP 'incorrectly' determining the contents of a variable. In the run whos output I quote, $type = 0. However, PHP doesn't seem to recognise this. Here is the code:

Code: Select all

if( $page == 1 )
{
if( $loc == 'ALL_LOCS' )
{
    if( $type == 'ALL_TYPES' )
    {
        echo 'PHP thinks that '.$type.' == ALL_TYPES!!';
    }
    elseif( $type != 'ALL_TYPES' )
    {
and here is the output, directly cut and pasted:

Code: Select all

PHP thinks that 0 == ALL_TYPES!!
Incidently, if I change the check for 'ALL_TYPES' to 'ABSOLUTE_GIMBOID' for example, I get exactly the same problem - it then seems to think that 0 == 'ABSOLUTE_GIMBOID'.

Can anyone shed any light on this problem? Why is it thinking that 0 is equal to any string I place in the if statement?

Many thanks

Mark

Posted: Thu Apr 28, 2005 1:39 pm
by shiznatix
were does $type come from?

Posted: Thu Apr 28, 2005 4:55 pm
by mjseaden
The $type variable is passed to a function stored in an 'include'd PHP script. The reason I have not looked very hard at the way it is parsed is because when echo'd, the variables do not match. $type is parsed as 0 to the function and appears as zero when echo'd.

I'm really confused by this problem - it appears that I can determine whether the variables are equal - but PHP/the computer can't!

Mark

Posted: Fri Apr 29, 2005 5:51 am
by timvw
i'm sorry, but i can't reproduce what you are experiencing...

Posted: Fri Apr 29, 2005 6:06 am
by phpScott
did the same used

Code: Select all

<?php
$page =1;
$loc = 'ALL_LOCS';

$type ='ALL_TYPES';

if( $page == 1 )
{
if( $loc == 'ALL_LOCS' )
{
    if( $type == 'ALL_TYPES' )
    {
        echo 'PHP thinks that '.$type.' == ALL_TYPES!!';
    }
    elseif( $type != 'ALL_TYPES' )
    {
        echo 'type '.$type.' != ALL_TYPES';
    }
}

}
    	
 ?>
but it works just fine for me.

you can try http://www.php.net/manual/en/function.gettype.php gettype() to see if it comes out as anything else.

There isn't a global variable some where else that might becausing something weird to be happening?