With instance members (non-static) I know we can, but with static members I DON'T KNOW IF WE CAN, if we can, is it good practice?
Asked
Active
Viewed 31 times
0
-
hi, might be of interest https://stackoverflow.com/questions/11331616/is-it-possible-to-declare-a-method-static-and-nonstatic-in-php – jspcal Jan 24 '23 at 17:41
-
hi @jspcal, nop, I say override static with static, not mix – Jan 24 '23 at 17:47
-
1Yes, you can override static methods. Try it and see. – Barmar Jan 24 '23 at 17:59
-
1As noted, this can [easily be proven](https://3v4l.org/hN53J). You should be aware of [late static binding](https://3v4l.org/c70VB), however. – Chris Haas Jan 24 '23 at 18:15
-
hi @Barmar, great (I already checked), if I would like to keep the parent functionality when I overwrite the parent static method in the child class, is it correct to use parent::parentStaticMethod() (I have doubts also on this)? – Jan 24 '23 at 18:40
-
Hi @Chris Haas then, if I need to override static members, IS IT BETTER TO OPT FOR LATE STATIC BINDING? – Jan 24 '23 at 18:43
-
Why are you shouting? – Chris Haas Jan 24 '23 at 18:44
-
sorry, it's just emphasis – Jan 24 '23 at 18:46
-
When you write a comment, there should be a little help link near by that will show you how to write **using emphasis** if you _really_ need to. But do consider if it is _really_ needed in the first place. – Chris Haas Jan 24 '23 at 18:47
-
1"Better" is subjective. Read the PHP article on LSB, make sure you understand it, and see if it even applies to your situation. Some people, including myself, generally prefer to avoid static methods whenever possible, and doubly so with inheritance. But that is a personal preference, and they are a 100% valid language feature. – Chris Haas Jan 24 '23 at 18:50
-
"Some people, including myself, generally prefer to avoid static methods whenever possible, and doubly so with inheritance". This matters to me, as I don't have much experience. If you want to reference parent static members from a child class (considering I don't use LSB), do you use `parent::`(I want to be sure of `parent::` in this case to avoid unwanted behavior))? – Jan 24 '23 at 19:07