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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]