fork download
  1. <?php
  2.  
  3. class Example {
  4.  
  5. private $name = '';
  6.  
  7. public function setName($name) {
  8. $this->name = $name;
  9.  
  10. // We return the object, so you can call it again.
  11. return $this;
  12. }
  13.  
  14. public function convertMtoN() {
  15.  
  16. // Let's do Caps first
  17. $this->name = str_replace("M", "N", $this->name);
  18.  
  19. // Then lowercase
  20. $this->name = str_replace("m", "n", $this->name);
  21.  
  22. // We return the object, keep working
  23. return $this;
  24. }
  25.  
  26. public function getName() {
  27. return $this->name;
  28. }
  29. }
  30.  
  31. $name = new Example;
  32.  
  33. echo $name->setName('Mike')->convertMtoN()->getName();
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Nike