|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Let's say I make a file like conf_global.php which contains the following:
PHP Code:
Basically it's a file containing global settings for my script. How would I use those vars on the rest of my script? Would just including the conf_global.php work?
__________________
![]() ![]() "Only Linux users see the end of crashes." - Pl4t0 |
|
#2
|
||||
|
||||
|
Yes, a simple include should work. If you need to use the variables in functions within the other scripts, you could either pass the array (or values) to the function or declare them global within each relevant function. Another approach is to build an object with set and get methods for various options and instantiate the object in each relevant page. This also makes it easy for you to have functions common to a bunch of files that can operate easily on the config options.
|
|
#3
|
|||
|
|||
|
if i include the file in the beginning of my script and just set 'global $myvar' right after making my class can i use it in all my functions?
|
|
#4
|
||||
|
||||
|
I believe you'd have to declare $myvar global within all functions. Using globals is typically considered bad practice. Better to pass as a param, in my opinion.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Making a global config file for a script? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|