Re: 'Undefined Variable' help...

From: Date: Tue, 04 Sep 2001 18:43:12 +0000
Subject: Re: 'Undefined Variable' help...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65922@lists.php.net to get a copy of this message
Hi Uchendu! Yes, this is very possible! Here are a few things that come to mind. There are of course many ways to do this : To check the existance of a variable, consider isset() as it checks for the existance of a variable : if (isset($HTTP_GET_VARS['images'])) Maybe set some default values for unset variables : if (!isset($width)) $width = 300; if (!isset($breads)) { $breads = array('rye','wheat','raison'); } A little debugging : <pre> <?php print_r($HTTP_GET_VARS); ?> </pre> A "Undefined Variable" Error is level E_NOTICE. More error handling information can be found here : http://www.php.net/manual/en/features.error-handling.php Doing the following will create a "Undefined Variable" Warning such as : if ($submit) // if (isset($submit)) echo $iamnotset; // if (isset($iamnotset)) echo $iamnotset; Warning: Undefined variable: submit in /home/http/file.php on line 24 Warning: Undefined variable: iamnotset in /home/http/file.php on line 25 Related places : Using Register Globals : http://www.php.net/manual/en/security.registerglobals.php Variables from outside PHP : http://www.php.net/manual/en/language.variables.external.php Configuration : error_reporting : http://www.php.net/manual/en/configuration.php#ini.error-reporting Hope that helps, good luck :) Regards, Philip Olson On Tue, 4 Sep 2001, Uchendu Nwachukwu wrote: > OK, I have a problem calling a function using default variables. > > In 'gallery.inc': > --------------------------------- > function gallery ($filename, $first = 1, $tablewidth = 4, $total = 20) { > echo "Filename: $filename, First image: $first, Table Width: > $tablewidth, Total: $total"; > } > --------------------------------- > > In 'gallery.php': > --------------------------------- > include('/path/to/gallery.inc'); > ... > gallery('test.txt',$first,$width,$images); > --------------------------------- > > $first, $width and $images are variables that are defined by the URL, as if > they were submitted through a form using HTTP GET, and they are designed to > be used like that. > > My problem is, if I don't define those variables in the URL when I run > gallery.php, PHP will come back with 'Undefined Variable' errors. Is there > any way I can prevent that from happening? > > TIA! > > -- > Uchendu Nwachukwu > unndunn AT yahoo DOT com - www.unndunn.com > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#65922) next »