Doing some code reviews lately I came across a number of classes that have significant number of static methods in them… and I can’t seem to grasp why? Hence my question:
What are the best practices regarding using static methods in PHP?
When would one want to use them and when would one shouldn’t use them?
What are specific difference in how runtime handles static methods? Do they affect performance or memory footprint?
PHP didn’t have namespaces before 5.3, so all function/variables would be in global scope unless they belonged in some class. Putting them in a class as static members is a workaround for not having namespaces (and that’s probably why you saw them in “significant” number)
Generally, they are used for functions that aren’t much useful in individual objects, but has some use at class level (as said in other answers)