Php object-oriented programming and other member attributes-PHP development

Source: Internet
Author: User
The variables directly declared in the class are called member attributes, or "fields" and "Features", but I often call them "attributes ". The member attribute declaration of a class is composed of a variable starting with the public keyword, protected, or private. The data type of this variable can be summarized as follows: Value Type 1. boolean Type 2. integer 3. float Type 4. double floating point type 4. string php surface and object programming ClassThe variables directly declared in are called member attributes or "fields", but also "Features". However, I often call them "attributes ". The member attribute declaration of a class starts with the keyword public, protected, or private, and then starts with a variable. The data types of this variable can be summarized as follows:

Value Type

1. boolean Type

2. integer

3. float

4. double floating point

4. string

Composite Type

1. array

2. The object is given

Special Type

1. resource

2. NULL

Class member attributesThe variables in can be initialized, for example:

 Male, "weight" => 150); // assign an array value for the attribute // public $ a = new A (); // PHP5 does not allow the creation of object types to be assigned to the attribute, an error is returned when you try to create $. // Public $ B = opendir ("abc"); // PHP5 does not allow resource types. An error occurs when you create a resource and copy it to $ B. // Public $ c = $ this-> age; // The attribute defined earlier cannot be used to assign values to the new attribute .} $ Person = new Person ();?>

Although you can assign an initial value to a variable when declaring a member attribute, it is not necessary to declare a class. For example, if you assign the name attribute of a person to "Zhang San", when you use this class instance to create multiple objects, everyone is Zhang San. Generally, the initial value is assigned to the corresponding member attributes after the class instantiates the 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.