In PHP5, the attribute definition can be set without setting the initial value, or given the following red type of initial value. There are 8 simple types in PHP, namely: • Numeric Type 1.boolean boolean type 2.integer integer 3.float float, also known as double-precision floating-point 4.string string • Composite type 1.array Array 2.object object · Special Type 1.resource resource 2. NULL 01 "Bar", + + true); Assign a value to a property using an array of//private $a = new A (); PHP5 not allowed, create object type assignment to attribute//private $res = Opendir ("abc"); PHP5 resource type not allowed//private $g = $this->grade; Assigning a value to a new property is not allowed with the previously defined property. $a = new person (); ?> in the example above, line 13th, attempting to create an object and assigning a value to property $ A will give an error. The 14th line, the creation of resources and replication to the $res error will occur. In line 15th, assigning a value to a new property using the attribute defined above also produces an error. In Java, you can do things like 13 lines and 15 lines. The default value of the attribute defined in PHP5 is limited to the simplest way. Other operations are given to the construction method, and the construction method is explained later in this section. The method of passing the value between the variable and the normal variable of the reference variable is the value assignment. such as arrays. 1 "Bar", + + true); 3 $a = $arr; 4 5 $arr [foo] = "new"; 6 Print_r ($arr); 7 Echo '
'; 8 Print_r ($a); 9?> Program output: View sourceprint?1 Array ([foo] = new [] + 1) 2 Array ([foo] = bar [] + 1) and the variable pointing to the object is A reference variable. Inside this variable is the memory address of the object being pointed to. When a reference variable passes a value, it is passed to the point of the object. Rather than copying this object. The extension of the $this property refers to the current object. $this, invokes the properties or methods of the current object. When you use $this-> to invoke an undefined property in a class, PHP5 automatically creates a property for use. The property that is created, the default method permission is public. 01 Age = "24"; : $p = new A (); Echo $p->name; Echo '
'; Echo $p->age; ?> program output: 1 gonn 2 24 attribute age was created.
http://www.bkjia.com/PHPjc/477753.html www.bkjia.com true http://www.bkjia.com/PHPjc/477753.html techarticle In PHP5, the attribute definition can be set without setting the initial value, or given the following red type of initial value. There are 8 simple types in PHP, namely: Numeric type 1.boolean boolean type 2.integer ...