What is the difference (if any, other than the syntactical) between these two forms of initialising class variables?
class example_1
{
private $bar = array();
public function __construct()
{
<other code>
}
}
class example_2
{
private $bar;
public function __construct()
{
$this->bar = array();
<other code>
}
}
Assuming both pieces of code are functionally equivalent, I prefer the code of example_1 because it's slightly shorter. My questions two are:
1) are the two forms really, truly functionally equivalent?
2) what are reasons -if any- to prefer one form over the other?
Thank you for any insights you're able to give me!
[Programmer's Promise: I will select a best answer as soon as I can. And I'm aware that selecting a best answer involves more than just giving a thumb up.
]
class example_1
{
private $bar = array();
public function __construct()
{
<other code>
}
}
class example_2
{
private $bar;
public function __construct()
{
$this->bar = array();
<other code>
}
}
Assuming both pieces of code are functionally equivalent, I prefer the code of example_1 because it's slightly shorter. My questions two are:
1) are the two forms really, truly functionally equivalent?
2) what are reasons -if any- to prefer one form over the other?
Thank you for any insights you're able to give me!
[Programmer's Promise: I will select a best answer as soon as I can. And I'm aware that selecting a best answer involves more than just giving a thumb up.
