Answer the question
In order to leave comments, you need to log in
Is it necessary in Symfony to specify required fields in the constructor when creating Doctrine entities?
Good afternoon!
Is it architecturally correct to specify mandatory properties (not null) in the constructor of doctrine entities?
class User {
private $username;
private $password;
// ...
private $propertyN;
public function __constructor($username, $password, $someElseProperty ... $propertyN)
{
$this->username = $username;
$this->password = $password;
$this->someElseProperty = $someElseProperty;
// ...
}
}
Answer the question
In order to leave comments, you need to log in
One of the developers of the doctrine advises to follow the principle:
Accordingly, passing required fields to the constructor is a good practice. See Doctrine best practices
slides .
The doctrine itself uses the reflection mechanism to set the data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question