fork(1) download
  1. <?php
  2.  
  3. class Classe {
  4. public function calcula(){
  5. $resultado = ($this->valor * 2);
  6. $this->valor = $resultado;
  7. return $resultado;
  8. }
  9.  
  10. public function valor(int $valor = 10){
  11. $this->valor = $valor;
  12. return $this;
  13. }
  14.  
  15. }
  16.  
  17. $classe = new Classe;
  18.  
  19. echo $classe->valor(2)->calcula();
  20. echo '<br>';
  21. echo $classe->calcula();
  22. echo '<br>';
  23. echo $classe->calcula();
  24. echo '<br>';
  25. echo $classe->calcula();
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
4<br>8<br>16<br>32