Advertisement
ph4x35ccb

Exercico cadastro Getter Setter Construct

Mar 14th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Cadastro</title>
  5. </head>
  6. <body>
  7. <pre>
  8.     <?php
  9.         require_once 'Cadastro.php';
  10.         $cad1 = new Cadastro();
  11.         $cad1-> setNome("Fulano");
  12.         $cad1->setSobrenome("Silva");
  13.         $cad1->setIdade(18);
  14.         $cad1->setEmail("Teste@teste.com");
  15.         $cad1->setSenha("Abc123");
  16.  
  17.         print_r($cad1);
  18.     ?>
  19. </pre>
  20.  
  21. </body>
  22. </html>
  23. //classe//
  24. <?php
  25.  
  26. class Cadastro{
  27.     private $nome;
  28.     private $sobrenome;
  29.     private $idade;
  30.     private $email;
  31.     private $senha;
  32.    
  33.     /*descomente e defina os valores na instancia
  34.      caso queira inicar com algum valor
  35.      $cad1("fulano","Silva","18","teste@teste","abc123");
  36.      public function __construct($n,$s,$i,$e,$s){
  37.         $this->nome=$n;
  38.         $this->sobrenome=$s;
  39.         $this->idade=$i;
  40.         $this->email=$e;
  41.         $this-senha=$s;
  42.      }
  43.     */
  44.  
  45.  
  46.     public function getNome(){
  47.         return $this->nome;
  48.     }
  49.     public function setNome($n){
  50.         $this->nome=$n;
  51.     }
  52.     public function getSobrenome(){
  53.         return $this->sobrenome;
  54.     }
  55.     public function setSobrenome($s){
  56.         $this->sobrenome=$s;
  57.     }
  58.     public function getIdade(){
  59.         return $this->idade;
  60.     }
  61.     public function setIdade($i){
  62.         $this->idade=$i;
  63.     }
  64.     public function getEmail(){
  65.         return $this->email;
  66.     }
  67.     public function setEmail($e){
  68.         $this->email=$e;
  69.     }
  70.     public function getSenha(){
  71.         return $this->senha;
  72.     }
  73.     public function setSenha($s){
  74.         $this->senha=$s;
  75.     }
  76. }
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement