I realize that it's possible to define a static class method as private and protected in PHP. This allows for an instantiated class, or public static method to access it's own private/protected static methods.
protected static function jumpOver ()
However I'm not sure if this is legal in the sense of OOP design. I can't find any real info stating it's ok to do this. I'm worried PHP may "patch" this in future versions if this is not a valid and break my scripts.
A static private method provides a way to hide static code from outside the class. This can be useful if several different methods (static or not) need to use it, i.e. code-reuse.
Static methods can be public or private. The static keyword is placed right after the public/private modifier and right before the type of variables and methods in their declarations.
Usually there isn't much reason to declare a private or protected method as static. Static methods are usually public. But when the behavior of a method does not affect or is affected by the state of the current instance, declaring it static can be a way to document this fact.
Yes, we can have private methods or private static methods in an interface in Java 9. We can use these methods to remove the code redundancy. Private methods can be useful or accessible only within that interface only. We can't access or inherit private methods from one interface to another interface or class.
It is. Static methods are usually nothing more than helper methods that have code you possibly don't want to be public.
The other common object-oriented languages I can think of have it too (C++, Java, C#). I really don't think they're ever going to remove that feature.
Besides, the guys at PHP are slow at breaking existing features, so I wouldn't worry too much about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With