I hope the moderator can provide great guidance on the writing of dynamic and static method calls in PHP.

Source: Internet
Author: User
I hope the moderator can provide great guidance on the writing of dynamic and static method calls in PHP.
 Db ;}} class B extends A {static function ex () {self: getInstance ()-> find () ;}}$ B = new B (); $ B-> find (); echo"
"; // Method B: ex ();?>

According to the description of the moderator, I modified it a little and made the current effect, but I don't quite understand it, because I am also confused and don't understand the specific principle.
First, I want to keep the find method in Class A written with the $ this pointer instead of self.
As in the following two call methods:
The first method dynamically calls the find method. Obviously, the output is OK.
The second type is the static class that calls the static method first. is The Returned "static instantiation object "?
And then call the find method. I don't know much about it. why is the $ this pointer changed?
The purpose of this writing is to allow external code to dynamically call or statically call methods in Class,
It's a bit confused,
Can the moderator organize the running principles?


Reply to discussion (solution)

Add one sentence below $ B = new B ();
$ B-> db = 2;

We can see that although it is a class, it contains two systems

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.