php isset problem

Discussion in 'Coding Help' started by Tom, Nov 11, 2011.

Tags:
  1. Tom

    Tom New Member

    Why would the code below ouput hello when it shouldn't? It's as if it's setting $test='hello' before any of the checks. Is there any reason this could be happening? This is a small piece of code from a bigger script but I'm not using $test anywhere outside of this code, even in other includes etc.

    Code:
    if (isset($test)){echo test;}
    if (!isset($test)){
        $test='hello';
    }
    

     
  2. php.allstar

    php.allstar New Member

    Hi,

    Which version of PHP are you using?

    It would be more helpful if you pasted your entire code... although as much as you protest, it would appear that $test is being set in the global scope somewhere.

    Put this before your code snippet and reply with the output:

    PHP:
    var_dump($test);
    exit();
     
  3. Tom

    Tom New Member

    ugh it's my fault, you're right, the code was in a file that I didn't realise was being included multiple times in a loop.
     

Share This Page