Created
June 24, 2022 18:25
-
-
Save elishaukpong/b91f02de2a8e4a2b4ac73f7a218e1d7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User { | |
protected $firstName; | |
protected $lastName; | |
protected $email; | |
public function setFirstName(string $firstName): self | |
{ | |
$this->firstName = $firstName; | |
return $this; | |
} | |
public function getFirstName(): string | |
{ | |
return $this->firstName; | |
} | |
public function setLastName(string $lastName): self | |
{ | |
$this->lastName = $lastName; | |
return $this; | |
} | |
public function getLastName(): string | |
{ | |
return $this->lastName; | |
} | |
public function setEmail(string $email): self | |
{ | |
$this->email = $email; | |
return $this; | |
} | |
public function getEmail(): string | |
{ | |
return $this->email; | |
} | |
public function __toString(): string | |
{ | |
return $this->getFirstName() . $this->getLastName(); | |
} | |
} | |
$user = new User(); | |
$user->setFirstName('John'); | |
// ->setLastName('Doe') | |
// ->setEmail('john.doe@example.com'); | |
echo $user->getFirstName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment