Last active
November 14, 2015 13:38
-
-
Save dwihujianto/8b0b3fedd7ccfc07185a to your computer and use it in GitHub Desktop.
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 | |
class Math | |
{ | |
protected $result = 0; | |
public function plus($value) | |
{ | |
$this->result += $value; | |
return $this; | |
} | |
public function minus($value) | |
{ | |
$this->result -= $value; | |
return $this; | |
} | |
public function result() | |
{ | |
return $this->result; | |
} | |
} | |
$cmobj = new Math(); | |
/* Common */ | |
$cmobj->plus(10); | |
$cmobj->minus(2); | |
echo $cmobj->result(); // 8 | |
/* Using method chaining */ | |
$mcobj = new Math(); | |
echo $mcobj->plus(13)->minus(3)->result(); //10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment