E
E
erastik2017-03-27 13:58:44
symfony
erastik, 2017-03-27 13:58:44

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

1 answer(s)
V
voronkovich, 2017-06-08
@voronkovich

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 question

Ask a Question

731 491 924 answers to any question