Three major features of php: encapsulation, inheritance, polymorphism, and Polymorphism

Source: Internet
Author: User

Three major features of php: encapsulation, inheritance, polymorphism, and Polymorphism

1. Encapsulation

Objective: To make the class safer

Practice: if the member variable is private, the member variable is indirectly operated through the method and the restriction conditions are added to the method.

Ii. Inheritance

Concept: subclass can inherit everything in the parent class.

Method Rewriting: override the method of the parent class in the subclass.

Feature: single inheritance: one subclass can have multiple parent classes, and one parent class can derive multiple child classes.

Override: Method Rewriting

Overload: overload, edit Polymorphism

Iii. polymorphism (running polymorphism)

Concept: the parent class references a subclass instance. Because the Child class overwrites the method of the parent class, the parent class references different States when calling this method.

Condition: 1 must occur under Integration

2. The parent class method must be overwritten.

3. The parent class references the call method.

If a method requires a parent class parameter, you can give a subclass object

Static
Common Member
Common members belong to objects.

Static Member
Static members belong to the class

Keyword: static
Self Keyword: indicates the class in the class
Common members cannot be called in static methods.
Static members can be called in common methods.


Interface
Extremely abstract class
The interface cannot contain member variables. It can only contain Member methods.
Member methods can have no function bodies
Interface Keyword: interface
The class that implements the interface. All methods in the interface must be implemented.

 

Loading class:
Include ("./Ren. class. php ");
Include "./Ren. class. php ";

Require ("./Ren. class. php ");
Require "./Ren. class. php ";

Require_once ("./Ren. class. php ");
Require_once "./Ren. class. php ";

Automatic class Loading Method
All class files should be placed in the same directory.
The naming rules of all class files are consistent.

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.