Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Created February 24, 2016 09:11
Show Gist options
  • Save kirilkirkov/d333f77df4f33d76bd5b to your computer and use it in GitHub Desktop.
Save kirilkirkov/d333f77df4f33d76bd5b to your computer and use it in GitHub Desktop.
php fluent interface pattern $obj->method1()->method2();
<?php
class User
{
protected $name;
protected $surname;
protected $password;
public function setName($name)
{
$this->name = $name;
return $this;
}
public function setSurname($surname)
{
$this->surname = $surname;
return $this;
}
public function setPassword($password)
{
if (!$password) {
throw new InvalidArgumentException("Password shouldn't be empty");
}
$this->password = $password;
return $this;
}
}
$user = new User;
$user->setName('John')->setSurname('Doe')->setPassword('root');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment