Php – Can PHP static methods legally have a visibility of protected or private

classoopPHP

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.

Best Answer

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.