Re: Defining own globals

From: Date: Wed, 14 Jan 2004 14:21:36 +0000
Subject: Re: Defining own globals
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-174550@lists.php.net to get a copy of this message
> > 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

« previous php.general (#174550) next »