Skip to content

Instantly share code, notes, and snippets.

@elishaukpong
Created June 24, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elishaukpong/b91f02de2a8e4a2b4ac73f7a218e1d7b to your computer and use it in GitHub Desktop.
Save elishaukpong/b91f02de2a8e4a2b4ac73f7a218e1d7b to your computer and use it in GitHub Desktop.
<?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