Answer the question
In order to leave comments, you need to log in
How to validate a large number of class properties?
Hello.
Suppose there is a certain web service that accepts user data as input: full name, gender, profession, city, etc., there are about 20 of them in total. All are required.
I need to work with this service.
To do this, I have a User class, which has a bunch of properties:
Class User {
private $lastName;
private $firstName;
private $city;
....
}
$user = new User();
$user->setLastName('Ivanov');
$user->setFirstName('Dmitriy');
$user->setCity('Moscow');
....
Answer the question
In order to leave comments, you need to log in
Use the __set and __get magic methods to avoid creating a bunch of getters and setters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question