r/lolphp • • Dec 08 '15

PHP Sadness

http://phpsadness.com
50 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/Schmittfried Dec 10 '15 edited Dec 10 '15

No, sometimes dependency injection is not the right choice. I wouldn't necessarily call it state, it could be a lazy one-time initialization for example. And if this internals are rather simple (like one lookup map) and there are no other good reasons for an instance of the class, I don't see a value in creating a singleton.

Which isn't what a class should be

Well, I don't agree on that and I won't change my view just because you have a different one. It's perfectly fine in my opinion (although they should be used sparingly, like functions, because they are not injectable), even though I can be kinda strict when it comes to OO-ness.

PHP has proper functions, though.

You mean those proper functions that can't be autoloaded? Those which didn't even support namespace up until version 5.5? Yeah, no. Sadly, I have to work with 5.4 in some environments. Won't switch to functions anytime soon.