Answer the question
In order to leave comments, you need to log in
Where is the best place to declare private properties?
Hello.
Tell me where you define private properties in the class.
At the beginning?
class A
{
private $items;
public function doSomthing()
{
return 'I done';
}
...
public function implodeItems()
{
return implode($this->items);
}
}
class A
{
public function doSomthing()
{
return 'I done';
}
...
private $items;
public function setItems(array $value)
{
$this->items = $value;
}
public function implodeItems()
{
return implode($this->items);
}
}
Answer the question
In order to leave comments, you need to log in
Variables are usually declared at the beginning of the file (and it doesn't matter if it's a class or just a file with functions)
At the beginning. The view may blur and miss the property declaration. And if they are all defined at the beginning, then, firstly, at the first glance at the class, it becomes clear what it operates with, and, secondly, if you forgot the property signature, then you just look at the beginning of the file and easily find it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question