Skip to content

Instantly share code, notes, and snippets.

@altayalp
Last active July 9, 2016 16:20
Show Gist options
  • Save altayalp/390d66f8dbc08a2349748b5b1a54eb6b to your computer and use it in GitHub Desktop.
Save altayalp/390d66f8dbc08a2349748b5b1a54eb6b to your computer and use it in GitHub Desktop.
Php fluent interface (aka method chaining) example
<?php
/**
* Person class
*
* @author altayalp <[email protected]>
*/
class Person
{
private $name;
private $surName;
public function __construct()
{
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function setSurName($surName)
{
$this->surName = $surName;
return $this;
}
public function getPerson()
{
echo "{$this->name} {$this->surName}";
}
}
$person = new Person();
$person->setName('John')->setSurName('Doe')->getPerson();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment