Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

* You can't extend a static method call - ie, it will always refer to a specific class, you can't replace it with another without changing a lot of calls.

* Lots of static calls are indicative of function classes - classes as namespaces for functions, and not a real OOP approach

There's nothing wrong with static calls per-se, but lots of them is a code smell in most cases.



One trouble with judging PHP like that is that the namespace features are so very new and almost universally loathed* that classes are/were the only widely-used form of namespace encapsulation.

In a language like Python, it's not uncommon to be far more discriminating about what is a class and what is just implemented using functions. That design is lost on PHP really.

*I disagree with the loathing. The backslash is a bit ugly but life goes on.


> You can't extend a static method call

You can as of PHP 5.3 with late static bindings. `static::function()` will use the inheritance chain to find `function`


That's an inner method call, that's not the use case I was referring to. When you call a static function from a different class, you put the class name before the call, and make it different to substitute it - which you could easily if you were dealing with an instance.

Example

MyClass::func();

func() Is tied to MyClass. if you extend it, you will have to hunt down all of those calls and replace it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: