Home > Backend Development > PHP Tutorial > Let's talk about the object-oriented understanding of PHP

Let's talk about the object-oriented understanding of PHP

烟雨青岚
Release: 2023-04-08 21:50:02
forward
2497 people have browsed it

Let's talk about the object-oriented understanding of PHP

php object-oriented

Today I will introduce to you the object-oriented nature of PHP. Speaking of object-oriented, I have to mention process-oriented, because when I first learned, I often couldn't distinguish between object-oriented and process-oriented.

Object-oriented programming (OOP) is a basic skill in our programming, and PHP5 provides good support for OOP. How to use OOP ideas to perform advanced programming of PHP is very meaningful for improving PHP programming capabilities and planning a good Web development architecture. Below we will use examples to illustrate the practical significance and application methods of using PHP's OOP for programming.

When we usually build a website with a database backend, we will consider that the program needs to be suitable for different application environments. What is different from other programming languages ​​is that in PHP, a series of specific functions are used to operate the database (if you do not use the ODBC interface). Although this is very efficient, the encapsulation is not enough. If there is a unified database interface, then we can apply it to a variety of databases without making any modifications to the program, thus greatly improving the portability and cross-platform capabilities of the program.

Let me introduce to you their differences:

Object-oriented focuses on which object handles a problem.

Its biggest feature is that it consists of classes with attributes and functions one by one, and gets objects from the classes to solve problems.

Process-oriented focuses on the process of solving a problem. Its biggest feature is that a series of processes are used to solve this problem one by one.

Object-oriented

1. What is a class?

A collection of a series of individuals with the same attributes (characteristics) and methods (behavior). A class is an abstract concept.

2. What is an object?

The individual with specific attribute values ​​obtained from the class is called an object. The object is a specific individual.

eg:Human;Zhang San

3. What is the relationship between classes and objects?

A class is an abstraction of an object! Objects are the reification of classes!

The class only indicates what attributes this type of object has, but cannot have specific values, so the class is abstract.

The object is a specific individual generated after assigning all attributes of the class. All objects are specific.

Class declaration and instantiation

1. How to declare a class:

class class name{

Access modifier$property[=default value];

[Access modifier] function method(){}

}

2. Statement Notes on a class:

① The class name can only be composed of letters, numbers and underscores. It cannot start with a number and must comply with the big camel case rule;

② The class name must be modified with class , there must not be ();

after the class name. ③ Attributes must have access modifiers, and methods do not need access modifiers.

3. Calling instantiated objects and object attribute methods: $object name = new class name(); //() can be used without

Calling properties and methods from outside the class: $object name-> $property name; //When using -> to call properties, the property name cannot contain the $ symbol

Call properties and methods inside the class Method : $this -> $Attribute name

Thank you for reading, I hope you will benefit a lot.

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of Let's talk about the object-oriented understanding of PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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