1331601238 Lujuu
Object-oriented programming has encapsulation, inheritance and polymorphism, in the PHP language, the definition of Java is roughly the same as class, followed by class name in class, you can declare the member method in the classes, when we need to use the method in the class we declare an object by the keyword new, in order to reduce the code, We can declare member variables in the class, declared by the keyword public, private, protected, static, final.
<?PHPclasssportobject{ Public $name;//Defining member Variables Public $height;//Defining member Variables Public $avoirdupois;//Defining member Variables Public functionBootfootball ($name,$height,$avoirdupois){//declaring member Methods $this->name=$name; $this->height=$height; $this->avoirdupois=$avoirdupois; if($this->height<185 and$this->avoirdupois<85){ return $this->name. ", meet the requirements of playing football!";//method implements the function}Else{ return $this->name. ", does not meet the requirements of playing football!";//method implements the function } }}$sport=NewSportobject ();//instantiate a class and pass parametersEcho $sport->bootfootball (' Tomorrow ', ' 185 ', ' 80 ');//methods in the execution class?>
The definition of a constant is declared by the keyword Const.
In PHP, the construction method is the same as Java, the constructor is used when initializing objects, if the class does not define a construction method, in the execution of the program will automatically generate a null parameter construction method, PHP in addition to the construction method has a destructor, the destruction method is the object is destroyed when the call, the role is to release memory, Of course, if there is no destructor, the system will automatically destroy the object when the program is finished, so the destructor is not used in PHP.
PHP Object-oriented