Page 1 of 1
Sin: Globals in OO PHP
Posted: Thu Jul 04, 2002 1:30 am
by Porter
I'd like to know what you guys think about using globals in OO PHP. I've thought about it for a while and asked a few people. Some claim it's how they were taught. Some, like me, claim it to be a huge sin. The poll is from 1 to 5(because I can't have it go up to 10). 1 being the lowest and 5 being the highest. huh? being you have no clue what I'm talking about.
Oh, I'm new here and it seems to be a great place to get help. I'm sure I'll stick around.
Posted: Thu Jul 04, 2002 1:34 am
by protokol
The whole point of OOP is to make your functions and variables localized to the object. The idea of encapsulation is very powerful and is the driving force behind the existence of OOP. Globals can ALWAYS be avoided.
In fact, the only time a global should be used is if it is a global constant. No variable should be global. If it is global, then you have a bad design. Period.
Posted: Thu Jul 04, 2002 1:40 am
by Porter
Glad to hear that you agree with me
Ever heard of Invisionboard? I'm sort of...how do you say, completely against it. I've seen more and more people using globals with oo php and I think it might just have somethign to do with it. The funny thing is that most people that use globals it that they use globals in the same way they would be using methods. It's really funny.
Posted: Thu Jul 04, 2002 6:44 am
by llimllib
While it is bad design, and not elegant to use globals in a completely OOP environment, wouldn't it be acceptable if one was tuning a program strictly for performance, and didn't want object overhead every time they needed the variable?
Globals and OOP
Posted: Thu Jul 04, 2002 9:51 am
by BDKR
Well, I too agree that Globals are prolly a bad idea in a purely OO environ, BUT, PHP isn't an ideal language to take a purely OO aproach. It's implementation of OO is lacking. Growing, yes, but lacking still.
However, I'm not religous about how things are ultimately implemented. You shoot for the very best, but optimize or tweak based on what's before you. And PHP OO is a bag full of work arounds.
But PHP still kicks butt!
Later on,
BDKR (TRC)