Home > Archive > PHP Language > May 2004 > global variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I have made a site where I need to be able to include a file containing an
array of settings in many pages. This array needs to have global scope for
use in and out of functions.
If I do this, I can't access the array inside functions:
include('file_with_array');
global $settings;
function wibble()
{
//can't access the array here unless I pass it in!
}
Does anyone know what I'm doing wrong or how to correct this?
Thanks
Ben
| |
| Alvaro G Vicario 2004-05-19, 12:30 pm |
| *** Ben wrote/escribió (Wed, 19 May 2004 14:59:50 +0100):
> global $settings;
>
> function wibble()
> {
> }
function wibble()
{
global $settings;
}
One more option I can think of is using constants:
define('DB_USER', 'foo');
define('DB_PASS', 'woo');
function wibble()
{
echo 'User is ' . DB_USER . ' and pass is ' . DB_PASS;
}
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
| |
|
| Ah, thank you. The constants turned out to be the best way to do it.
"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
message news:1f7nf0nzatom3.1crvji25oo83q$.dlg@40tude.net...
*** Ben wrote/escribió (Wed, 19 May 2004 14:59:50 +0100):
> global $settings;
>
> function wibble()
> {
> }
function wibble()
{
global $settings;
}
One more option I can think of is using constants:
define('DB_USER', 'foo');
define('DB_PASS', 'woo');
function wibble()
{
echo 'User is ' . DB_USER . ' and pass is ' . DB_PASS;
}
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
|
|
|
|
|