Monday, 11 December 2017

What exactly are late static bindings in PHP?

itemprop="text">

What exactly are late static bindings
in PHP?



itemprop="text">
class="normal">Answer



You
definitely need to read href="http://php.net/manual/en/language.oop5.late-static-bindings.php"
rel="noreferrer">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 self keyword does not follow the same
rules of inheritance. self always 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, self will not reference the child as you
might expect.



Late static binding introduces a
new use for the static keyword, which addresses this particular
shortcoming. When you use static, 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, parent and
static operate when static is 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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...