Re: question on avoiding abuse of global
Jerry Stuckle wrote:
> lazy 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.
>>
>
> No. For your code to know about them, you must define them somewhere. A
> file which is included in others is as good as any - and quite
> efficient. But efficiency shouldn't be your problem right now anyway.
> Get it working; if you have performance problems. find the cause of your
> performance problem and fix it. Including a configuration file will not
> be the problem.
The OP said "alternative to including config.php". What he can do is to
declare some session variables in config.php, and then use them
elsewhere without including config.php. So, the answer to that part is
"yes".
>
>> 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.
>>
>
> Check out the define().
>
|