|
Late Static BindingsAs of PHP 5.3.0, PHP implements a feature called late static bindings which can be used to reference the called class in a context of static inheritance.
This feature was named "late static bindings" with an internal perspective in
mind. "Late binding" comes from the fact that
Static references to the current class like Example 10.42. self:: usage<?php The above example will output: A
Late static bindings tries to solve that limitation by introducing a
keyword that references the class that was initially called at runtime.
Basically, a keyword that would allow you to reference
Example 10.43. static:: simple usage<?php The above example will output: B
Note:
Example 10.44. static:: usage in a non-static context<?php The above example will output: TestChild
Note:
Late static bindings' reslution will stop at a fully resolved static call with no fallback. Example 10.45. Fully resolved static calls<?php The above example will output: A There are lots of different ways to trigger a method call in PHP, like callbacks or magic methods. As late static bindings base their resolution on runtime information, it might give unexpected results in so-called edge cases. Example 10.46. Late static bindings inside magic methods<?php The above example will output: B |
Change LanguageIntroduction The Basics Autoloading Objects Constructors and Destructors Visibility Scope Resolution Operator (::) Static Keyword Class Constants Class Abstraction Object Interfaces Overloading Object Iteration Patterns Magic Methods Final Keyword Object cloning Comparing objects Reflection Type Hinting Late Static Bindings |