Link to home
Start Free TrialLog in
Avatar of trickyidiot
trickyidiot

asked on

PHP: defined constants versus class-defined variables - need some valid opinions

I'm in the beginning stages of building a very large application and I'm at a cross-roads.

Do I create an include file that uses define() to define a plethora of constants for all vars used application-wide allowing me to reference them like this:
echo "This is something and " . SOME_VALUE . "<br />";

OR

Do I create a class, instantiated by the core class that houses all of the variables, allowing me to reference them like this:
echo "This is something and {$this->main->coreVariables->someValue}<br />";

I want opinions from the experts on performance, tidy-ness, best practice, etc.

I will award points evenly between everyone, excluding those who merely post nonsense to get free points.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru 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
about this comment and continuing taking about good OOP style:
>> The main performance problems when building big php application is the bootstrapping
>> of you framework to include all necessary classes
If you need a constant than belongs a class, then you need the class, unless you have placed the constant in the wrong class.
Avatar of trickyidiot
trickyidiot

ASKER

Thinking more into it, Jaime is right in that having all my vars in one place, rather than in the classes they are referenced is a bad idea.
I will have my database vars defines inside my database class, my navigation vars inside my output formatting class, etc.
So far as managing the application goes, it makes more sense.
Were I building this application to be duplicated for multiple companies, I would have gone more with a configuration file approach, but since this is for one company, I will go ahead with the separation by class.

Thank all of you for your input. I am splitting the points evenly as promised.
-=Patrick=-