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.