Object-oriented thinking PHP object-oriented concepts

WBOY
Release: 2016-07-29 08:47:13
Original
1012 people have browsed it

Keywords and special variables
new, class, extends. Everyone knows these three.
::, the scope resolution operator (also known as Paamayim Nekudotayim) or more simply a pair of colons, can be used to access static members, methods and constants. Can also be used to override members and methods in a class.
parent and self. parent refers to the name of the base class pointed to by the derived class in the extends declaration. Doing this avoids using the base class name in multiple places.
$this pseudo variable. $this points to the current instance. $this is not necessarily the object to which the method belongs. Sometimes code within class A will call a static method of class B. Reference example: http://www.php.net/manual/zh/language.oop5.basic.php
static keyword. If you declare a class member or method as static, you can access it directly without instantiating the class. However, except for static methods, static members cannot be accessed through an object. In static methods, $this is not used. Instead use self:: .
final keyword. It can be used on classes and functions, so that classes cannot be inherited and methods cannot be overridden.
Attribute
 Can be initialized, but the initialized value must be a constant. Use the const keyword in front of a constant. The value of the constant must be a fixed value and cannot be the result of a variable, class attribute or other operation (such as a function call).
Constructor and destructor
Neither of these two functions will secretly call the response function of the base class, which is different from the constructor mechanism of Java. To achieve this effect, execution must be displayed. Exceptions cannot be thrown in the destructor.
Abstract class: Class methods declared as abstract cannot contain concrete implementations, and abstract classes cannot be instantiated. Must be inherited first, and then instantiate its subclass. Moreover, the access control of subclasses should be the same as that of abstract classes, or more relaxed. An abstract class contains at least one abstract method.
Interface
Using an interface, you can specify which methods a class must implement, but you do not need to define the specific content of these methods.
All methods defined must be public, and the methods are empty
Constants can be defined, but there are no attributes
Interface implementations must implement all methods, and can implement multiple interfaces (note that methods cannot have the same name).
Interfaces can be inherited by other interfaces (extends)

The above introduces the object-oriented thinking and PHP object-oriented concept, including the content of object-oriented thinking. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!