[ not posted to alt.php ]
Leigh Riley wrote:
Hi,
Can someone tell me if the following is possible?
I have a file containing some STATIC variables, and some functions e.g.
-------------------------------------------------
$ARCHIVE_INPUT_FILES = false;
$ARCHIVE_OUTPUT_FILES = false;
$ARCHIVE_CONFIG_FILES = false;
$HTML_BODY_BACKGROUND = "gfx/gradient.gif";
function firstOne
{
// Do something e.g.
echo $HTML_BODY_BACKGROUND;
}
-------------------------------------------------
The functions CANNOT see the variables I have declared at the top, so is
there anything I can do make the functions see the variables i.e.
declare them differently?
Well ... if they're STATIC variables make them constants :-)
That way you can see them inside the functions
<?php
define('ARCHIVE_INPUT_FILES', false);
define('ARCHIVE_OUTPUT_FILES', false);
define('ARCHIVE_CONFIG_FILES', false);
define('HTML_BODY_BACKGROUND', 'gfx/gradient.gif');
?>
Failing that you can declare the variables global in the function:
<?php
function firstOne
{
global $ARCHIVE_INPUT_FILES, $ARCHIVE_OUTPUT_FILES;
global $ARCHIVE_CONFIG_FILES, $HTML_BODY_BACKGROUND;
// Do something e.g.
echo $HTML_BODY_BACKGROUND;
}
?>
or maybe access the $GLOBAL array inside the function
<?php
function firstOne
{
// Do something e.g.
echo $GLOBALS['HTML_BODY_BACKGROUND'];
}
?>
Happy Coding :-)
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.