Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

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.
SOLUTION
Avatar of Lacca
Lacca
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

I am not sure if $_session works in a procedural function and an object oriented class.
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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks for teaching me that a variable can have different values inside functions, classes