In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of static binding in the later stage of php, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Late static binding works by storing the class name of the previous "non-forwarded call" (non-forwarding call). When making a static method call, the class name is the one explicitly specified (usually in the left part of the:: operator); when a non-static method call is made, it is the class to which the object belongs.
The so-called "forward call" (forwarding call) refers to static calls made in several ways: self::,parent::,static:: and forward_static_call (). You can use the get_called_class () function to get the class name of the method being called, and static:: indicates its scope.
Limitations of self::
A static reference to the current class using self:: or _ _ CLASS__, depending on the class in which the current method is defined:
Example:
Class A {public static function who () {echo _ CLASS__;} public static function test () {self:: who ();}} class B extends A {public static function who () {echo _ CLASS__;}} B:: test ()
Results:
Astatic (later static binding)
Late static binding was intended to bypass the limitation by introducing a new keyword to represent the class originally called by the runtime. Simply put, this keyword allows you to refer to class B instead of A when you call test () in the above example. In the end, it was decided not to introduce new keywords, but to use the reserved static keyword.
Example:
Results:
The difference between Bstatic and $this
In a non-static environment, the class invoked is the class to which the instance of the object belongs. Because $this- > tries to call private methods in the same scope, static:: may give different results. Another difference is that static properties can only be called with static::.
Example: calling a private method
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.