Advertisement
ph4x35ccb

tratamento de exeçoes

Apr 8th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. require 'Cliente.php';
  4.  
  5. try{
  6.     $cli = new Cliente;
  7.  
  8.     $cli->setNome('ca');
  9.  
  10.     $cli->setEmail('Teste@teste.com');
  11.  
  12.     var_dump($cli);
  13.  
  14. }catch(Exception $ex){
  15.     echo "Logar erro: ".$ex->getMessage();
  16. }
  17. ///classe cliente////
  18.  
  19. <?php
  20.  
  21. class Cliente
  22. {
  23.     protected $nome;
  24.     protected $email;
  25.  
  26.     public function setNome($nome)
  27.     {
  28.         if(mb_strlen($nome,'utf8')< 3){
  29.             throw new Exception('Nome deve ter mais que 2 caractere');
  30.             ;
  31.         }
  32.         $this->nome=$nome;
  33.     }
  34.  
  35.     public function setEmail($email)
  36.     {
  37.         if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
  38.             throw new Exception('Email invalido');
  39.            
  40.         }
  41.         $this->emial=$email;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement