PHP Object-oriented-abstract a class

Source: Internet
Author: User

First, abstract a class

1. Concept:

Object: Entity of an objective transaction

Class: An abstract description of an entity

Class cannot be used directly, only after instantiation (new) can be used

2, naming: The name of the class is equivalent to the name of the function, note: The class name is case-insensitive (variable names are case-sensitive)

Class: Capitalize the first letter of all words such as goodpeople

Method (function): Initial letter of the first word is capitalized after the first letter of the word, such as Loadsay

3. Composition

A class can define member methods (functions) or you can define member properties (variables)

4. Declaration of Class

"Some modified keywords" class name {

Members of the class;

}

5. Attributes of a member (a variable declared directly in a class)

Example 1-1:class person{

var $name;

var $sex;

var $age;

}

Note: When declaring a member property in a class, it is important to use a keyword before the variable, and if you do not need to have a specific adornment, use the "var" keyword, and if there are other keywords in the member properties, you need to remove "var" keyword, you can only have member properties and member methods inside a Class!!! There can be no other, there cannot be two classes of the same name in a script , the instantiation class may have multiple objects

Example 1-2:class person{

Public $name; Shared Permissions

Private $sex; Private Permissions

Static $age; Static Permissions

}

3.methods of the members (functions declared directly in the class)

Example 1-3:class person{

function say () {

method Body

}

}

PHP Object-oriented-abstract a class

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.