Questions about PHP-> (CALL) and: (two colons)

Source: Internet
Author: User
Learning PHP: Class mypc {static public $ name = "my computer"; function show () {echo $ this-> name. "starting ...... ";}} Under normal circumstances: $ P = new mypc (); $ p-> show (); this is OK, however, the show method mypc: Show (); PHP does not report an error, which leads to doubts. I used to do. net. Everyone knows that static classes can be called by class name and method name. In PHP, the explanation for: Is also a static member of the call class. However, this show method does not have the static keyword, that is, it is not an explicit static method. Please note that this "display ". In. net, if there is no static keyword, the class name cannot. PHP does not seem to have this restriction. After using this method, it seems that the show method is automatically called as a static method. In this way, if the entire class is a method without considering the attribute issue, why should I use the new class? I have asked for a half-day question on the PhP100 forum, and I have no very accurate answer. I can only think that PHP is automatically converted to a static method, so you don't have to go to the new object to open up a new memory address, you can directly use the method of this class. This method will also exist as a member attribute of this class, without occupying the independent memory because of the new object. In this case, an error is reported if the static variable $ name is removed. The attributes in the method must also be static before they can be called. In addition, this pair of non-static attributes cannot be called. For example, after the static attribute of $ name is removed, mypc: $ name cannot be called. The benefits are also obvious. The ability to automatically convert to a static method reduces the memory loss. In the course of learning, I have encountered such a problem so far. How can I use it ~~ Hope to hear more answers ~~ Love fight

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.