Possible Duplicate:
Initializing Class Fields at the Field Definition or in Class Contructor
Setting variables on Constructor VS on the class definition
What is the difference (if any) between the following 2 examples, and what is the proper way to initialize object properties?
Please note that the content of $fields in this case is something predefined, it will not change in runtime.
Example 1:
class User
{
$fields = array('username', 'password', 'email');
function __construct()
{
}
}
Example 2:
class User {
$fields;
function __construct()
{
$this->fields = array('username', 'password', 'email');
}
}
The first example… It is more explicit and obvious to the reader what the intention of
$fieldsis… “something predefined“