What does PHP mean in a class where new itself stands? is a constructor function

Source: Internet
Author: User
What does a class in his class method new itself represent? Is the constructor??


Reply to discussion (solution)

The new class name is used to create an instance of this class, which is the same everywhere, and there is no difference in usage

Your DB class declares a private constructor, so this DB class cannot be instantiated externally
So to write in the interior

Do you put the editor in a fancy, no-cost eye?

So the constructor is back in the past! Face this is more than face a white piece of black a lot of this is desktop background ... Sublimetext with plug-in transparent

This is your own new. You can also write new self like this. The landlord of this class is to achieve single-class use. You can only instantiate yourself.

Looks like a singleton pattern.
$instance is a static variable, getinstance is a static method
When this class is used outside, the object that is called directly by Db::getinstance is already new, and no matter how many times it is called, the same object is returned, guaranteeing that the object is a singleton

This is your own new. You can also write new self like this. The landlord of this class is to achieve single-class use. You can only instantiate yourself.


This avatar is very

hahaha I found that now a lot of developers are like to make the editor Holi fancy .... We are really old.

This is a singleton pattern.

hahaha I found that now a lot of developers are like to make the editor Holi fancy .... We are really old.



I'm sorry about the whole class.
  • Related Article

    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.