Members and constants in classes in PHP

Source: Internet
Author: User
Tags constant definition

Overview of members in a class

Object-oriented programming is the need to do something through an "object" (to accomplish some sort of task);

and

Objects are always derived from classes;

So:

Object-oriented programming, everything begins with a defined class;

the members of the class are divided into 3 categories :

Property:

Method:

Constant:

form, roughly as follows:

class name {

constant definition 1;

constant Definition 2;

.......

attribute definition 1;

attribute definition 2;

........

method definition 1;

method definition 2;

.......

}

Description

Above, there is no order problem; In practice, the constants are put in front, then the attributes, then the methods;

In detail, it is also divided into:

Property:

Common Properties;// general properties, instance properties

static properties;

Method:

common method;// general method, instance method

static method;

Construction method;

Destruction method;

Constant:

class Constants

when a constant is defined in a class, the constant is called a "class constant"-essentially a constant;

definition form:

class name {

Const constant name = constant value;

You cannot use define () to define it!

}

form of Use:

The use of constants is through the class name and is used with the range resolver (::);

class Name:: Constant name ;

Example:

Members and constants in classes in PHP

Related Article

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.