Last active
October 29, 2015 13:03
-
-
Save klhall1987/93f23c527ebb845af55e to your computer and use it in GitHub Desktop.
Method Chaining with phones
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 Phone | |
{ | |
//Creating private properties | |
private $_type; | |
private $_os; | |
public function setType( $type ) | |
{ | |
//setting private property equal to the $type variable. | |
$this->_type = $type; | |
//returning the private property that has been set to the $type variable. | |
return $this; | |
} | |
public function setOS( $os ) | |
{ | |
//setting private property equal to the $os variable. | |
$this->_os = $os; | |
//returning the private property that has been set to the $os variable. | |
return $this; | |
} | |
public function getPhone() | |
{ | |
//returns a sting with the properties being called | |
return 'I have a(n) ' . $this->_type . ' running ' . $this->_os . '.'; | |
} | |
} | |
$phone = new Phone(); | |
//returns:"I have a(n) HTC One M8 running Android Lollipop." | |
echo $phone->setType('HTC One M8')->setOS('Android Lollipop')->getPhone(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment