rgb192
asked on
a global config variable that can be read from everywhere
I have procedural code mixed with object oriented code
Computes my hours and shows emails so I can present to client
so I want to work on code at the same time to make more re-usable
but there are many limitations
I have two separate table names for two companies, because I do not want to mix data.
So I would different php file for each company.
So I have to find and replace the tablename.
Maybe a config variable would be easier.
How to have a config variable that can be in object oriented classes and procedural functions.
I know that globals are bad but my old code is so disorganized.
Computes my hours and shows emails so I can present to client
so I want to work on code at the same time to make more re-usable
but there are many limitations
I have two separate table names for two companies, because I do not want to mix data.
So I would different php file for each company.
So I have to find and replace the tablename.
Maybe a config variable would be easier.
How to have a config variable that can be in object oriented classes and procedural functions.
I know that globals are bad but my old code is so disorganized.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The variable $config has no special meaning in PHP.
okay, for this example because I do not want to write many lines of code to start session and read session from every class method, how can I set a global variable one time and be able to read the global variable in every procedural function and object oriented class method on the same page?
Yes I read many times that global is bad but this code is not public and global may be the solution for this example and I will learn why global is bad by using in this example.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for teaching me that a variable can have different values inside functions, classes
ASKER
I may have to create and read the session in many times in the code.
what is a config variable
I have been asking experts-exchange questions about code where
$config['default_username'
$config['default_password'
and I think these variables can be read throughout the code
but is it just using the word '$config' that makes this possible?