This article mainly describes PHP object-oriented programming methods. In PHP, we can use classes like C ++ and C # To encapsulate some of the methods we commonly use and then call them when instantiating them.
Constructor:
Class mypc {
Function _ construct (){
Initialization
}
}
Destructor:
Class mypc {
......
Function _ destruct (){
......
}
}
Encapsulation keywords: public, protected, private
Encapsulate related functions: __set (), _ Get ()
_ Set (): Obtain the private attributes encapsulated in the current class or re-execute or assign values to the methods.
_ Set ($ name, $ value)
_ Get () gets the encapsulated attributes or methods in the current class and converts them to common attributes.
_ Get ()
Eg:
<? PHP
Class mypc
{
Private
$ Name;
Public
$ Type;
Function
_ Construct ($ name = '')
{
Return
$ This-> name = $ name;
}
Private
Function power ()
{
Return
$ This-> name. "power on, starting ...";
}
Function _ Get ($ name)
{
Return
$ This-> name ."---";
}
Function _ set ($ N, $ V)
{
If ($ v> = 100)
$ This-> $ n = $ V;
}
}
$ PC1 = new mypc ('My pc ');
$ PC1-> name = 30;
Echo $ pC1-> name;
?>
Inheritance Keyword: extends
Base Class Name: Method Name
Abstract keywords: Abstract
At least one method in a class is abstract, which is called an abstract class.
Therefore, if an abstract class is defined, the abstract method is first defined.