Normal Properties (instance properties):
the word for the instance is:instance
examples, in fact, also called "Object";
A normal (instance) attribute is a property that can be used on an object that is instantiated from that class!
definition form:
class name {
var $ Property name = initial value;
var $ property name; // This property has no initial value;
the above var can also be replaced with public , such as:
Public $ Property name = initial value;
Public $ Property name; // This property has no initial value;
}
form of Use:
Is through the object of the class to use the normal attribute (instance property):
$ Object , property name;
Because the nature of a property is a variable, it can be viewed and used as a variable, such as:
Property name $v 1 = $ Object ;
echo $ Object , property name;
$v 2 = $ Object , property name * 3 + 5; // calculation
Static properties:
A static property, which is essentially a "variable", has one characteristic: the variable is only subordinate to the "class", i.e.:
A static property in a class , only "One piece of data";
But:
An instance attribute in a class can have "multiple data"--each object is created with a copy of the data;
definition form:
class name {
Static $ Property name = initial value;
Static $ property name; // This property has no initial value;
}
form of Use:
use the class name and Range Resolver (::) to manipulate the static properties:
class Name:: $ static property name; // Note: property name with $ symbol
contrast 1:
Use of constants: Class Name:: Constant name;
contrast 2:
use of Instance properties: Object Name , instance property name; // Note: Property name does not have a $ symbol
The result is:
Visible:
1, the instance property, is each object can be different data, is also each object "own" the data;
2, static property, which he does not belong to any object, but belongs to the class itself, but also can be understood as a common data for all objects;
Common and static properties in PHP