Re: question on avoiding abuse of global
- From: Gordon <gordon.mcvey@xxxxxxxxxxxx>
- Date: Tue, 24 Jun 2008 04:58:16 -0700 (PDT)
On Jun 22, 4:08 pm, lazy <arunm...@xxxxxxxxx> wrote:
hi,
I have some constants defined in a php script say config.php.
I want to use the variables there defined in other scripts.
couple of questions regd that:
1. Is there an alternative to including config.php and declaring the
variables that will be used as global. This seems very inefficient.
2.Moreover these variables are constants, is there a way to make the
variables unmodifiable in config.php so that scripts that use them ,
dont overrite them. Is there a php construct which can delare a
variable as constant.
The clue is in your question. You say that what the config file
contains should be considered constants, but you're actually declaring
them as variables.
As you want constants you really should be using define() to declare
them.
Constants defined with define() are different from variables declared
in the global scope. Firstly their value is immutable, in other words
constant, and secondly they don't require use of the global()==
keyword in blocks that aren't in the global scope. They are
automatically usable from anywhere in your code provided the file that
holds them has been included.
.
- References:
- question on avoiding abuse of global
- From: lazy
- question on avoiding abuse of global
- Prev by Date: Re: Upload a file question
- Next by Date: Re: Force user to another page
- Previous by thread: Re: question on avoiding abuse of global
- Next by thread: How to make image of web page
- Index(es):
Relevant Pages
|