Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. class pessoa{
  4. public $nome;
  5. function scr_nome($nom) {
  6. $this -> $nome = $nom;
  7. }
  8.  
  9. function ver_nome(){
  10. return $this -> $nome;
  11. }
  12. }
  13.  
  14. $mulher = new pessoa();
  15. $mulher -> scr_nome("Maria Paula");
  16. echo $mulher -> ver_nome();
  17.  
  18.  
  19. ?>
  20.  
  21. <?php
  22.  
  23. class pessoa{
  24.  
  25. private $nome; // importante isso ser uma variável privada da classe já que tem um método de acesso a ela
  26.  
  27. function setNome($nom) {
  28. $this->nome = $nom; // Aqui voce colocou o cifrão, isso retira a propriedade
  29. }
  30.  
  31. function getNome(){
  32. return $this->$nome;
  33. }
  34. }
  35.  
  36. $mulher = new pessoa();
  37. $mulher->setNome("Maria Paula");
  38. echo $mulher->getNome();
  39.  
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement