Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does php oop mean?

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what does php oop mean?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php oop refers to object-oriented programming. in object-oriented programming (OOP), object is a whole composed of information and the description of information processing, and it is an abstraction to the real world.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

What does php oop mean?

PHP object oriented

In object-oriented programming (English: Object-oriented programming, abbreviation: OOP), an object is a whole composed of information and the description of information processing, and is an abstraction of the real world.

In the real world, the things we face are all objects, such as computers, televisions, bicycles and so on.

There are three main properties of an object:

The behavior of the object: those actions can be applied to the object. Turning on and off the light is the behavior.

The shape of the object: when those methods are applied is how the object responds, color, size, appearance.

The representation of the object: the representation of the object is equivalent to the ID card, specifically distinguishing what is different in the same behavior and state.

For example, Animal (animal) is an abstract class, we can be specific to a dog and a sheep, and dogs and sheep are specific objects, they have color attributes, can write, can run and other behavior states.

Object-oriented content

The class − defines the abstract characteristics of a thing. The definition of the class includes the form of the data and the manipulation of the data.

The object − is an instance of the class.

The member variable − is defined as a variable within the class. The value of the variable is invisible, but it can be accessed through a member function, and after the class is instantiated as an object, the variable becomes a property of the object.

The member function − is defined inside the class and can be used to access the data of the object.

Inheriting − inheritance is a mechanism by which subclasses automatically share parent data structures and methods, which is a relationship between classes. When defining and implementing a class, it can be done on the basis of an existing class, taking the content defined by the existing class as its own content, and adding some new content.

Parent class − A class that is inherited by another class can be called a parent class, or a base class, or a superclass.

Subclass − A class that inherits other classes is called a subclass, or a derived class.

Polymorphic − polymorphism means that the same function or method can act on many types of objects and obtain different results. Different objects can produce different results when they receive the same message. This phenomenon is called polymorphism.

Overloaded − simply means that functions or methods with the same name but different parameter lists are called overloaded functions or methods with different parameters.

Abstract − abstraction refers to the abstraction of objects with consistent data structures (attributes) and behaviors (operations) into classes. A class is such an abstraction that reflects important properties related to the application while ignoring other irrelevant content. The division of any class is subjective, but it must be related to the specific application.

Encapsulation − encapsulation refers to binding the attributes and behaviors of an object that exists in the real world and placing them in a logical unit.

The constructor − is mainly used to initialize the object when it is created, that is, to assign an initial value to the object member variable, which is always used in the statement that creates the object together with the new operator.

The destructor − destructor (destructor), in contrast to the constructor, automatically executes the destructor when the object ends its life cycle (for example, the function in which the object is located has been called). Destructors are often used to clean up the aftermath (for example, opening up a memory space with new when creating objects, which should be freed with delete in the destructor before exiting).

In the following figure, we create three objects through the Car class: Mercedes, Bmw, and Audi.

$mercedes = new Car (); $bmw = new Car (); $audi = new Car ()

PHP class definition

The general syntax format of the PHP definition class is as follows:

The resolution is as follows:

The class uses the class keyword followed by the class name definition.

Variables and methods can be defined in a pair of curly braces ({}) after the class name.

Variables of a class are declared using var, and variables can also initialize values.

The function definition is similar to the definition of the PHP function, but the function can only be accessed through the class and its instantiated object.

Example

The variable $this represents its own object.

PHP_EOL is a newline character.

Create objects in PHP

After the class is created, we can use the new operator to instantiate the object of the class:

$runoob = new Site;$taobao = new Site;$google = new Site

In the above code, we have created three objects, all of which are independent. Let's take a look at how to access member methods and member variables.

Call member method

/ / call member functions, set title and URL$runoob- > setTitle ("Rookie tutorial"); $taobao- > setTitle ("Taobao"); $google- > setTitle ("Google search"); $runoob- > setUrl ('www.runoob.com'); $taobao- > setUrl (' www.taobao.com'); $google- > setUrl ('www.google.com'); / / call member functions to get title and URL$runoob- > getTitle (); $taobao- > getTitle (); $google- > getTitle () $runoob- > getUrl (); $taobao- > getUrl (); $google- > getUrl ()

The complete code is as follows:

Example

Execute the above code, and the output is as follows:

Rookie tutorial Taobao Google search www.runoob.comwww.taobao.comwww.google.com "what does php oop mean" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report