PHP Static Binding Details

Source: Internet
Author: User
Tags php oop

This article simply describes the static bindings in PHP, for the static bindings in PHP is not so familiar with the students can take a look at this article about the static binding of PHP Oh!

Late static binding works by storing the class name on the previous "non-forwarding call" ( non-forwarding call ).

    • When a static method call is made, the class name is the one explicitly specified (usually in the left part of the: operator);

    • When a non-static method call is made, the class to which the object belongs.

The so-called "forwarding Call" ( forwarding call ) refers to static calls made in the following ways: self:: , parent:: static:: as well forward_static_call() . get_called_class()a function is available to get the class name of the method being called, and static:: its scope is indicated.

Self:: the limit

Use self:: or a static reference to the current class, depending on the class in which the current method is defined:

Cases:

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:

A

Above all the content of this article, we have seen after must feel very confused, I hope you can combine examples to see and achieve their own two articles!

Related recommendations:



PHP late static binding instance sharing

PHP OOP post-term static binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.