What exactly are late static bindings in PHP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You definitely need to read Late Static Bindings in the PHP manual. However, I’ll try to give you a quick summary.
Basically, it boils down to the fact that the
selfkeyword does not follow the same rules of inheritance.selfalways resolves to the class in which it is used. This means that if you make a method in a parent class and call it from a child class,selfwill not reference the child as you might expect.Late static binding introduces a new use for the
statickeyword, which addresses this particular shortcoming. When you usestatic, it represents the class where you first use it, ie. it ‘binds’ to the runtime class.Those are the two basic concepts behind it. The way
self,parentandstaticoperate whenstaticis in play can be subtle, so rather than go in to more detail, I’d strongly recommend that you study the manual page examples. Once you understand the basics of each keyword, the examples are quite necessary to see what kind of results you’re going to get.