PHP5 object orientation (learning record)

  • 2020-03-31 17:06:09
  • OfStack

1. Inheritance extends can only be inherited single
Public protected private property
__construct ()
__destruct ()
S) to read private members
S/s set($n,$v) to set private members
2, access to the parent function :: (c++ inside also called scope character)
7
3. Overloaded functions with the same superclass name

The abstract class abstract must be inherited and cannot be instantiated and must override the abstract function as long as one of the functions in the class is static

5. Commonly used keywords
1, the function cannot be overloaded when the class cannot be inherited when the class is defined in final
2, self is used to access properties or methods (static or constant) in an uninstantiated class using the method self:: property
3. Static defines a static member or method that appears in memory only once (no non-static content can appear in a static method)
Const defines constants that can only be modified by member attributes without adding $
6, the application interface interface of the interface defines the keyword implements reference
Interface: all abstract methods, do not add the abstract property should be a constant
Interface Demo {}
Class T implements Demo{} can refer to multiple interfaces
Class a extends root implements Demo{}
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 an object is passed to a function as an argument, the constructor is not run and the object's address is passed instead of a copy

9, object description configure s/s s tostring(){content} directly echo object

Object exception handling with s $name ($value) automatically absorbs your error and displays the value of $name and error parameters when calling a nonexistent method name

11, object cloning with clone clone() in the clone keyword (equivalent to c++ copy function)

Function ss ($class_n){
Include ($class_n. 'PHP');
} a class inlcude() is automatically loaded when a new class is created

Related articles: