Gleidson_21

getter_and_setter

Jul 29th, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2. // setter e getters
  3. class Login
  4. {
  5.   private $email;
  6.   private $senha;
  7.  
  8.   public function getEmail()
  9.   {
  10.     return $this->email;
  11.   }
  12.   public function setEmail($e)
  13.   {
  14.     $email = filter_var($e, FILTER_SANITIZE_EMAIL); // filtraNDO EMAIL
  15.     $this->email = $email;
  16.   }
  17.   public function getSenha()
  18.   {
  19.     return $this->senha;
  20.   }
  21.   public function setSenha($s)
  22.   {
  23.     $this->senha = $s;
  24.   }
  25.  
  26.   public function logar()
  27.   {
  28.     if ($this->email == "teste@teste.com" and $this->senha == "12345") :
  29.       echo "Logado com sucesso";
  30.     else :
  31.       echo "Dados invalidos";
  32.     endif;
  33.   }
  34. }
  35. $logar = new Login();
  36. $logar->setEmail("teste//()@teste.com"); // FOI FILTRADO
  37. $logar->setSenha("12345");
  38. $logar->logar();
  39.  
  40. echo "<br>";
  41.  
  42. echo $logar->getEmail();
  43. echo $logar->getSenha();
  44.  
Add Comment
Please, Sign In to add comment