Php object-oriented BASICS (3) and php object-oriented Basics
1. Static *
Common Member: belongs to the object
Static member: belongs to the class
Keyword: static
Class FenBi
{
Public $ length = 10; // chalk length, common member
Public static $ color = "red"; // chalk color, static member
Public static function test ()
{
Echo "static member method". self: $ color; // self class, which can also be implemented using the class name FenBi
}
Public function ceshi ()
{
Echo self: $ color;
}
}
$ F = new FenBi ();
$ F-> length; // call method of common members
$ F-> ceshi ();
FenBi: $ color; // call method of static members
FenBi: test (); // static member method. Common members cannot be called.
2. Abstraction
Keywords: abstract
Abstract classes cannot be instantiated because they are too abstract. They exist as parent classes.
The abstract method cannot contain the function body. Its specific functions are implemented in the subclass through rewriting.
Classes that contain abstract methods must be abstract classes.
Abstract class DongWu
{
Public $ name;
Abstract public function test (); // The function body does not need to be added because it is too abstract {}
}
Class Dog extends DongWu
{
Public function test () // rewrite
{
Echo "Rewrite ";
}
}
$ D = new Dog ();
Var_dump ($ d );
3. classes with extremely abstract Interfaces
No member variables in the interface
All member functions in the interface are abstract
Interface IUSB
{
Public function read (); // read Method
Public function write (); // write Method
}
Class ShuBiao implements IUSB
{
Public function read ()
{
Echo "insert mouse ";
}
Public function write ()
{
Echo "write content to the mouse ";
}
}
$ S = new ShuBiao ();
$ S-> read ();