Last active
July 9, 2016 16:20
-
-
Save altayalp/390d66f8dbc08a2349748b5b1a54eb6b to your computer and use it in GitHub Desktop.
Php fluent interface (aka method chaining) example
This file contains hidden or 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 | |
/** | |
* 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