I am just looking through some core files of Codeigniter and I see that it uses some what you might call procedural functions scattered all over the place like to get the instance of the config class somewhere in a core class instead of injecting it into the object it just does
$config =& get_config();
I’m no expert but isn’t that bad to do? To me it seems like making the application have unnecessary global state.
As far as I can see it is nearly the exact same as doing something like
$config = App::loadClass('config');
Is doing it the second way worse than the first? I’m thinking it might be because when calling it the second way the App class needs to exist (and be located) and doing it the first way no specific class must exist and the class file does not need to be included so less requirements.
I am making my own framework and have avoided using any static stuff so far but when I look into the code of the leading frameworks for ideas or help I see static stuff all over the place and I wonder why?
You would think that the leading frameworks would be coded a bit better or maybe using global methods is not as harmful as many people make them out to be what do you think?
In my framework I have to inject this $config object into lots of classes and a $logger object and a $messages/$language and a few more. I use a Dependency Injection container and factories but it’s still a bit of a pain compared to just doing
$config = App::loadClass('config');
$someSetting = $config->setting('some.setting');
Logger::write('debug', 'some message');
If I’m going to use static methods should I use the procedural ones(Codeigniter example) or the ones embedded in classes? or do you strongly advise to never use them?
Any opinions would be great thanks.
Correct. This should be avoided. Not only does it introduce global state, but it also spits out a
strictwarning:Is doing it the second way worse than the first?
Don’t think it is worse, because at least you don’t get the `Strict Standards` warning. But still you would really want to avoid this.
> I am making my own framework and have avoided using any static stuff so far but when I look into the code of the leading frameworks for ideas or help I see static stuff all over the place and I wonder why?
This is because of the fact that most popular frameworks out there are terrible. Not only do they introduce bad coding practice, but often they also will also tell you it is using a MVC structure (which most are clearly not).
> You would think that the leading frameworks would be coded a bit better or maybe using global methods is not as harmful as many people make them out to be what do you think?
Again those frameworks are full of WTF’s. If you really think you want to look into one of the popular frameworks you should look into Symfony 2 or Zend FW 2. Not because they do everything the correct way, but because they are the best (of the popular ones) imho.
> In my framework I have to inject this $config object into lots of classes and a $logger object and a $messages/$language and a few more.
Dependency injection is the correct way to solve this (at least if you are going for an OOP approach). However if you classes have a lot of dependencies you might have to stop for a moment and think about the fact the perhaps your classes are doing too much. A.k.a they have [too many responsibilities](http://en.wikipedia.org/wiki/Single_responsibility_principle).
> If I’m going to use static methods should I use the procedural ones(Codeigniter example) or the ones embedded in classes? or do you strongly advise to never use them?
Strongly advice against both. As you already stated in introduces global state. Make testing a pain. And has more to do with procedural programming than OOP.
*P.S. I have giving you the two best FW’s in my opinion. If you want to know CodeIgniter and Cake are the worst.*
To finish this post a somewhat related message from [the PHP chatroom](https://chat.stackoverflow.com/transcript/11?m=6055399#6055399) by [Lusitanian](https://chat.stackoverflow.com/users/1477526/lusitanian):
> *Microframework* (n): A small amount of crap. See also *Framework* (n): A large amount of crap.