Re: [PHP] Defining own globals

2004-01-14 Thread Chris Boget
> > Would it be possible to make all hard-coded variables beginning with $_
> > automatically global? I've found useful to set some variables per page
> > to $_PAGE variable (for example $_PAGE['title'] etc) that would be nice
> > to get available to all functions without extra procedures (like global
> > command). The best way could be that $_ variables can't be defined by
> > any user-input (forms, cookies etc)...
> > Well, that's a explanation. I hope that someone would give any hint
> > concerning this subject. :)
> You already have $GLOBALS as a global (scope wise) variable, just add to
> that if you want.
> $GLOBALS['page_title'] = 'etc';

Or, if you want/need to be really anal about naming conventions, you can 
do something along the following (continuing from John's example):

$GLOBALS['_PAGE']['title'] = 'Page Title';
$GLOBALS['_PAGE']['css_file'] = '/some/absolute/path/css_file.css';

function whatever() {

  $_PAGE = &$GLOBALS['_PAGE'];

  echo $_PAGE['title'];
  echo $_PAGE['css_file'];

}

Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Defining own globals

2004-01-14 Thread CPT John W. Holmes
From: "Ville Mattila" <[EMAIL PROTECTED]>

> Would it be possible to make all hard-coded variables beginning with $_
> automatically global? I've found useful to set some variables per page
> to $_PAGE variable (for example $_PAGE['title'] etc) that would be nice
> to get available to all functions without extra procedures (like global
> command). The best way could be that $_ variables can't be defined by
> any user-input (forms, cookies etc)...
>
> Well, that's a explanation. I hope that someone would give any hint
> concerning this subject. :)

You already have $GLOBALS as a global (scope wise) variable, just add to
that if you want.

$GLOBALS['page_title'] = 'etc';

Or you can add directly to $_GET, $_POST, etc, so long as it doesn't
interfere with your forms. Maybe you need to use $_SESSION. Bottom line, the
variables are already there, just use them.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Defining own globals

2004-01-14 Thread Ville Mattila
Hello,

Would it be possible to make all hard-coded variables beginning with $_ 
automatically global? I've found useful to set some variables per page 
to $_PAGE variable (for example $_PAGE['title'] etc) that would be nice 
to get available to all functions without extra procedures (like global 
command). The best way could be that $_ variables can't be defined by 
any user-input (forms, cookies etc)...

Well, that's a explanation. I hope that someone would give any hint 
concerning this subject. :)

Best regards,
Ville
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php