PHP Object-oriented

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.