Answer the question
In order to leave comments, you need to log in
Is this an exceptional situation?
For example, there is a class that in the constructor receives some input that is needed to initialize the object.
For example:
class User {
private ?array $userData;
public function __construct(int $userId) {
$this->userData = ...;
// ...
}
// ...
public function getId(): int {
return $this->userData["ID"];
}
public function getFullName(): string {
return implode( " ",
clearArray( [
$this->userData["NAME1"],
$this->userData["NAME2"],
$this->userData["NAME3"]
] )
);
}
public function getLogin(): string {
return $this->userData["LOGIN"];
}
public function getEmail(): string {
return $this->userData["EMAIL"];
}
}
Answer the question
In order to leave comments, you need to log in
Specific parameters
must be passed to the entity : $id
, $login
, and not an array $userData
from which you need to extract this data, check their type and existence. With this approach, you can use typing and be confident in the data passed.
You can also create an entity with different factory methods .
The exception must be in your repository 's get() method . And don't confuse find() and get() methods :
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question