Php object-oriented basics, php object-oriented

Source: Internet
Author: User

Php object-oriented basics, php object-oriented
Three main characteristics of the Face Image direction: encapsulation, inheritance, and polymorphism Abstraction:

When we first define a class, we actually extract the common attributes and behaviors of a class of things to form a physical model (Template). This method of research is called abstraction.

Encapsulation:

Encapsulation is to encapsulate the extracted data and the operations on the data, and the data is protected internally. Only authorized operations (methods) in other parts of the program can perform operations on the data.

Inheritance: inheritance is a subclass that persists the attributes and methods of the parent class through the parent class. polymorphism refers to multiple forms, which have the ability to express multiple forms. Objects are processed in different ways based on the object type. Polymorphism allows each object to respond to common messages in a suitable way. Polymorphism enhances the flexibility and reusability of software. class in object-oriented systems:

Class is used to describe an Object ):

Class describes the data that each object should contain, and class describes the behavior characteristics of each object.

Class member definition method:

Public $ aa; common, indicates global. This class can be accessed inside, outside, and subclass.

Private $ aa; private variable, accessible only to this class or subclass

Protect; protected variables, subclass can also be used

This is to define this object (instantiated object)

-> Get the xx in it, which is equivalent to.

Constructor method:

<? Phpclass jsq {public $ a; public $ B; public function _ construct ($ x, $ y) // _ construct () {} constructor, define a, B {$ this-> a = $ x; $ this-> B = $ y;} public function jia () directly here () {return $ this-> a + $ this-> B;} // AB instantiate public function jian () {return $ this-> a-$ this-> B ;} public function chen () {return $ this-> a * $ this-> B;} public function chu () {return $ this-> a/$ this-> B ;}$ suan = new jsq (3, 4); // class instantiation echo $ suan-> jian (); ?>

 

 

 

Everything is Object: Everything is an Object.

 

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.