Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User
- {
- private $name;
- private $surname;
- private $username;
- public function __construct(string $name, string $surname, string $username)
- {
- if($this->validate($name)) {
- $this->name = $name;
- }
- if($this->validate($surname)) {
- $this->name = $surname;
- }
- if($this->validate($username)) {
- $this->name = $username;
- }
- }
- public function validate(string $input): bool
- {
- if (strlen($input) < 5 && !preg_match('~[0-9]~', $input)) {
- return false;
- } return true;
- }
- public function getInfo(): string
- {
- return 'Name of the user is: ' . $this->name . ', surname is: ' . $this->surname . ' and username is: ' . $this->username;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement