Re: weird isset problem

From: Date: Thu, 29 Mar 2001 23:03:10 +0000
Subject: Re: weird isset problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-46177@lists.php.net to get a copy of this message
What are you wanting to print? Here's a set of examples that may help understand what's happening with your code. In short, isset() is not being used properly. // if $var is set, this will return 1. if not set then it will return 0. // essentially, you don't want to print this directly as you've seen, it // gives us 1 or 0. isset($var) // these checks check for true. if ( isset($var) == true ) { print 'this is set'; } if ( isset($var) == 1 ) { print 'this is set'; } if ( isset($var) ) { print 'this is set'; } // these checks check for false. if ( isset($var) == false ) { print 'this is not set'; } if ( isset($var) == 0 ) { print 'this is not set'; } if ( !isset($var) ) { print 'this is not set'; } // This will check whether $var is empty but this way causes error if // error_reporting setting E_NOTICE is on (undefined variable) if ($var) { print 'this is set'; } Which brings us to empty(), empty is similar to isset, here's an example of difference : $var = 0; if ( empty($var) ) { print 'this will print if $var is not set,0, or empty "" '; } if ( isset($var) ) { print 'this is set, could be set to anything, including 0 or "" '; } Wow this got long, hopefully it makes sense :) regards, philip On Thu, 29 Mar 2001, Matthew Hanna wrote: > Hi! I have this weird thing happening here and I just can't see the problem. > Can someone look at this and tell me if you see what is wrong? > Below is a code snippet I am using and the output from the code. As can > be seen in the output all the $config[*] stuff are set. The if statement still > gets executed though as if one or more $config[*] isn't set. Inside of the > if statement I checked again and sure enough, they are still set even though > the program makes it into the if statement. > I am so confused. > > Thanks in advance! > Matthew Hanna > hanna@clemson.edu > > ---- Code ---- > print isset($config["harvester_list"]) ."\n1\n"; > print isset($config["download_list"]) . "\n2\n"; > print isset($config["linkchecker_list"]) . "\n3\n"; > print isset($config["offline_list"]) . "\n4\n"; > print isset($config["spider_list"]) . "\n5\n"; > if (!isset($config["havester_list"]) || > !isset($config["download_list"]) || > !isset($config["linkchecker_list"]) || > !isset($config["offline_list"]) || > !isset($config["spider_list"])) { > print "-----------------------------\n"; > print isset($config["harvester_list"]) ."\n1\n"; > print isset($config["download_list"]) . "\n2\n"; > print isset($config["linkchecker_list"]) . "\n3\n"; > print isset($config["offline_list"]) . "\n4\n"; > print isset($config["spider_list"]) . "\n5\n"; > > die("Agent Automated System Lists Not Found!\n"); > } > > ---- Output ----- > 1 > 1 > 1 > 2 > 1 > 3 > 1 > 4 > 1 > 5 > ----------------------------- > 1 > 1 > 1 > 2 > 1 > 3 > 1 > 4 > 1 > 5 > Agent Automated System Lists Not Found! >

« previous php.general (#46177) next »