Skip to content

Instantly share code, notes, and snippets.

@gmilby
Created July 19, 2013 21:20
Show Gist options
  • Save gmilby/6042441 to your computer and use it in GitHub Desktop.
Save gmilby/6042441 to your computer and use it in GitHub Desktop.
class SimpleCounter {
protected $total = 0;
public function add($amount)
$this->total += $amount
return $this
}
public function subtract($amount)
$this->total -= $amount
return $this
}
public function getTotal()
return $this->total;
}
}
And now...
$counter = new SimpleCounter();
echo $counter->add(5)
->subtract(3)
->add(2)
->getTotal();
// 4
echo $counter->getTotal();
// 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment