Home > Backend Development > PHP Tutorial > Detailed introduction to the structure of classes

Detailed introduction to the structure of classes

零下一度
Release: 2023-03-10 09:32:01
Original
1320 people have browsed it

This article mainly introduces the difference between the constructor _construct() and _initialize() of the class in ThinkPHP. The introduction is very detailed. I believe it has certain reference value for everyone. Friends who need it can read it together. Take a look. Preface I believe that PHPers who are familiar with THINKPHP are basically familiar with the _initialize() method. It seems that we rarely use _construct() unless we write a plug-in ourselves, otherwise it is really rarely used. Looking at the code today, I suddenly saw _construct(), the construction method that comes with PHP. My first impression was that it was relatively unfamiliar. Although I often encountered it when I was learning Java before, I have basically forgotten it after a long time. My usual habit is to write down the key points of knowledge in my small notebook, but since I haven’t written for a long time, the elegant and flexible writing style I used to have in high school has completely disappeared into another dimension. In addition to the previous thoughts, I came to learn how to write blogs from technology experts. This is not to show off, but just to prevent every bit of the results of my work from dissipating with the passage of time. Let’s take a look at the detailed introduction. Paste the code first (my environment is wamp

1. About _construct() method instance summary

Detailed introduction to the structure of classes

Introduction: This article mainly introduces the difference between the constructor _construct() and _initialize() of the class in ThinkPHP. The introduction in the article is very detailed. I believe it will be useful to everyone. For reference, friends in need can take a look below. Preface I believe that phpers who are familiar with THINKPHP are basically familiar with the _initialize() method. We rarely use _construct() unless we write a plug-in ourselves. It’s really rarely used. When I looked at the code today, I suddenly saw _construc...

##2. Detailed introduction to _initialize()

Detailed introduction to the structure of classes

Introduction: This article mainly introduces the difference between the class constructor _construct() and _initialize() in ThinkPHP. The introduction is very detailed and I believe it has certain reference value for everyone. Friends who need it can take a look below. Preface I believe that phpers who are familiar with THINKPHP are basically familiar with the _initialize() method, and we rarely use it. _construct() is rarely used unless you write a plug-in yourself. I looked at the code today and suddenly saw _construc...

3. Ten things about PHP Introduction to six magic methods

Detailed introduction to the structure of classes

Introduction: Methods starting with two underscores __ in PHP Called magic methods, these methods play a crucial role in PHP. Magic methods include: __construct(), the constructor of the class

##4.

Detailed explanation C# class construction method and sample code

Detailed introduction to the structure of classes##Introduction: This article mainly introduces the c# class construction method. It has certain reference value. Let’s take a look at it with the editor.

5.

Introduces in detail the constructors _construct() and _initialize() of classes in ThinkPHP Difference

Detailed introduction to the structure of classesIntroduction: This article mainly introduces the constructor _construct() and the class constructor in ThinkPHP The difference between _initialize() is introduced in great detail in the article. I believe it has certain reference value for everyone. Friends who need it can take a look below.

6.

JAVA Summary of Abstract Classes and Interfaces

Introduction: 1. Abstract class a) Subclasses of abstract classes must override all abstract methods of the parent class i. If not, unless the subclass itself is also an abstract class; b) Whether the abstract class Are constructors allowed? i. Allow! (Check after class), explanation: The constructor of the drawing class has another clever application: it is to implement the code that the subclass must execute inside it. 2. Myeclipse usage details a) In MyEclipse, a triangle will be displayed on the left

7. C# Basic knowledge arrangement: Basic knowledge (3) Class structure

Detailed introduction to the structure of classes

Introduction: Therefore, there must be such a method in the class, with no return type, the method name is the same as the class name, and Parameter class list or no parameter list. It is the construction method, commonly known as "constructor" or "constructor". A class can have one or more constructors. Of course, sometimes you do not write a constructor. This does not mean that the class does not have a constructor. It still has a default constructor. If multiple constructors are used, their respective parameter lists must be different.

8. JavaScript object-oriented - inheritance based on function forgery

Detailed introduction to the structure of classes

##Introduction: Since there are some shortcomings in the way of implementing inheritance based on the prototype chain, people have adopted another way to implement inheritance-implementing inheritance based on function forgery. The idea of ​​this technique is to call the parent class's constructor inside the child class's constructor.

9. Constructor cannot be a virtual function

Detailed introduction to the structure of classes

##Introduction: The reasons why constructors cannot be declared as virtual functions: 1. The so-called virtual function means that only one is executed in polymorphic situations. From the concept of inheritance, the parent class object is always constructed first, and then the subclass can be Object, if the constructor is set to a virtual function, then you have to explicitly call the constructor when constructing the constructor of the parent class. Another reason is to prevent errors from happening. Just imagine if you accidentally make a mistake in the subclass. If you rewrite a function that is the same as the parent class constructor, then your parent class constructor will be overwritten, that is, the construction of the parent class cannot be completed, and an error will occur. class A{ ...

10.

Constructor call of anonymous inner class in java

Detailed introduction to the structure of classes

Introduction: Discuss the construction method of anonymous inner classes with others, write the code yourself and see what the principle is like. Because the class is anonymous, there is no way to create a constructor with the same name. But you can directly call the constructor of the parent class. The test code is as follows:

[Related Q&A recommendations]:

Why does a subclass in python explicitly call the constructor of the parent class

c++ - When using the current dll to encapsulate another dll, is there any way to export the entire dll of a class in another dll?

javaInput an integer and print n lines in the following way. If n=4, the generated arrangement will be: 1*2*3*4 *17*18*19*20

javascript - Doubts about class and super in ES6

oop - Why must the parent class constructor be executed in java?

The above is the detailed content of Detailed introduction to the structure of classes. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template