Explain 'Late Static Binding' and the difference between self:: and static::.
Last updated
self::is fixed at compile time to the class where the code is written, ignoring which subclass called it.static::(Late Static Binding) resolves to the class actually called at runtime, so it respects inheritance.Typical use: parent static factories like
new static()that return the calling subclass.
- https://www.php.net/manual/en/language.oop5.late-static-bindings.php
- https://dev.to/dev-alamin/exploring-late-static-binding-in-php-2d2b
- https://dev.to/edriso/understanding-static-vs-self-in-php-3bm2
- https://medium.com/@hossamsoliuman/late-static-binding-in-php-20024b352f6d
- https://medium.com/@annxsa/why-static-class-vs-self-class-matters-more-than-you-realize-ebe9aa0dd2c6
- https://medium.com/@emad-mohamed/late-static-binding-b1ba6286b9be
- https://utkrusht.ai/blog/php-interview-questions