search
HomeBackend DevelopmentPHP ProblemHow to understand the php construction method

How to understand the php construction method

Oct 11, 2019 am 11:50 AM
phpConstruction methodunderstand

How to understand the php construction method

What is a constructor method

The constructor method is a special method of a class, its main function is to complete the initialization of new objects.

Features:

1. No return value

2. When creating a new object, the system will automatically call the constructor of the class Complete the initialization of the new diagonal

    语法:
    php5:        修饰符 function __construct()
                        {
                            //code
                        }
    php4:        修饰符 function 类名()
                        {
                            //code
                        }

Note:
1. PHP5 supports both. If both construction methods exist at the same time, the first one is preferred

2. A class has an empty constructor without parameters by default. Once a constructor is customized, the default constructor will be overwritten, so a class has and only one constructor.

3. A class can only have one constructor. (It cannot be overloaded)

4. The default access modifier of the constructor is public.

Recommended tutorial:PHP video tutorial

The above is the detailed content of How to understand the php construction method. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment