fork download
  1. <?php
  2. class Cliente {
  3. private $id;
  4. private $nome;
  5. public function __construct($id = 0, $nome = NULL){
  6. $this->id = $id;
  7. $this->nome = $nome;
  8. }
  9. public function getId(){
  10. return $this->id;
  11. }
  12. public function getNome(){
  13. return $this->nome;
  14. }
  15. public function setId($value){
  16. $this->id = $value;
  17. return $this;
  18. }
  19. public function setNome($value){
  20. $this->nome = $value;
  21. return $this;
  22. }
  23.  
  24. public function __set ($name,$value){
  25. $this->$name = $value;
  26. }
  27. public function __get ($name){
  28. return $this->$name;
  29. }
  30. }
  31.  
  32.  
  33. $cliente = new Cliente();
  34.  
  35. $cliente->setId(2)
  36. ->setNome("Fulano 2");
  37.  
  38. echo $cliente->id . " " . $cliente->nome;
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
2 Fulano 2