Home >Backend Development >PHP Tutorial >PHP5 object-oriented (learning record)_PHP tutorial

PHP5 object-oriented (learning record)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:42:27900browse

1. Inherit extends and can only inherit
public protected private attributes
__construct()
__destruct()
__get() to read private members
__set($n,$v) to set private Member
2, access the parent class function:: (also called scope symbol in C++)
7
3, overload the function with the same name as the parent class

4, abstract class abstract It must be inherited and cannot be instantiated and abstract functions must be overridden. As long as one function in the class is static, the class must be static

5, common keywords
1, final When defining a class, the class cannot When an inherited function is defined, the function cannot be overloaded
2. self is used to access properties or methods (static or constant) in uninstantiated classes. Use the method self::attribute
3. static defines static members or methods only It will appear once in the memory (non-static content cannot appear in static methods)
4. Const defined constants can only modify member properties. Modified constants do not add $
6. Interface application interface interface definition keyword implements reference
Interface: All methods are abstract, no need to add abstract attributes. They should be constants
interface Demo{}
class T implements Demo{}. Multiple interfaces can be referenced
Inherit first and then interface class a extends root implements Demo {}
Interface inherits interface interface D extends Demo

7, polymorphic PHP is a weakly typed language, so the support is not perfect
instanceof tests whether an instance comes from a class example: a{} $c = new a; if($c instanceof a)
8, When the object is passed to the function as a parameter, the constructor is not run and it is not a copy, but the object address is passed

9, Object description configuration_ _tostring(){content} Directly echo the object

10, object exception handling __call($name,$value) automatically absorbs your error when calling a non-existent method name and displays the value of $name and error parameters

11, object cloning __clone() is placed in the class with the clone keyword (equivalent to the copy function of c++)

12, automatic loading function __autoload($class_n){
include($class_n.'php');
} Automatically load inlcude() a class when creating a new class by yourself

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320986.htmlTechArticle1, inherit extends and can only inherit the public protected private attribute __construct() __destruct() __get() to read Private member __set($n,$v) sets private member 2 and accesses the parent class function:: (in c++...
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