Php Getting Started Tutorial (1/5)

Source: Internet
Author: User
Tags constant modifier

Class declaration:

 

The code is as follows: Copy code

<? Php
Permission modifier class name {// permission modifier: public, protected, private, or omitted 3.
// Class body; // class is the key word for creating a class
} // The class name must be followed by the class and followed by the member of the class placed.
?>
// Ps: you can add a permission modifier before the class keyword, static, abstract, and other keywords. A class, that is, all the content between a pair of braces must be in a piece of code, and the content in the class cannot be divided into blocks.
<? Php
Class ConnDB {
//....
?>
<?

//...
};
?>

 

Member attributes:

The variables directly declared in the class are called member attributes/Variables. They can be of the scalar type and compound type in php, and the resource type and null type are invalid.

In addition, when declaring a member attribute, you must have a keyword to modify it: public, protected, private; no specific significance is required: var. when declaring a member attribute, there is no need to assign an initial value.

 

Member constants:

Modified with a const constant, for example, const PI = 3.1415926;

Constant output does not need to be instantiated. It can be directly called by class name + constant name. The format is: class name: constant name

Ps. Special access methods: -------- "$ this" and "::"

1) $ "this" exists in each member method, which is a special object to use. the member method belongs to that object, and the $ this application represents that object. Its function is to complete access between members of the object.

2) ":" becomes the scope operator. With this operator, you can call constants, variables, and methods in the class without creating objects. The syntax format is as follows:

Keywords: variable name/constant name/method name

Keyword: parent, which can call the member variables, member methods, and constants in the parent class member;

Self, which can call static members and constants in the current class;

Class name, which can call constants, variables, and methods in the class;

Member method:

A function declared in a class becomes a member method. Multiple functions can be declared in a class, that is, an object can have multiple member methods. the declaration of the member method is the same as that of the function. The only special feature is that the member method can be modified with keywords to control its access permissions.

Class instantiation

Creation object:

$ Variable name = new class name ([parameter]); // class instantiation.

Member class:

$ Variable name-> member attribute = value;

Homepage 1 2 3 4 5 Last page
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.