Advertisement
ph4x35ccb

Getter Setter e Construtores

Mar 14th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5.     <title>Exercio 04b</title>
  6. </head>
  7. <body>
  8. <pre>
  9. <?php
  10.  
  11. require_once 'Armario.php';
  12. $arm1 = new Armario("Camiseta","Calças","Shorts");
  13. //$arm1-> setGaveta1("Camisetas");
  14. //$arm1-> setGaveta2("Calças");
  15. //$arm1-> setGaveta3("Shorts");
  16. echo "<br>";
  17. print_r($arm1);
  18. echo "<br>";
  19. echo "Gaveta 1 {$arm1->getGaveta1()} , gaveta 2 {$arm1->getGaveta2()} e gaveta 3 {$arm1->getGaveta3()}";
  20.  
  21. ?>
  22. </pre>
  23. </body>
  24. </html>
  25. //Classe//
  26. <?php
  27.  
  28. class Armario{
  29.  
  30.     private $gaveta1;
  31.     private $gaveta2;
  32.     private $gaveta3;
  33.     private $fechar;
  34.    
  35.     public function __construct($g1,$g2,$g3){
  36.         $this->gaveta1=$g1;
  37.         $this->gaveta2=$g2;
  38.         $this->gaveta3=$g3;
  39.         $this->fecha();
  40.     }
  41.     public function fecha(){
  42.         $this->fechar=true;
  43.     }
  44.     public function getGaveta1(){
  45.         return $this->gaveta1;
  46.     }
  47.     public function setGaveta1($g1){
  48.         $this->gaveta1=$g1;
  49.     }
  50.     public function getGaveta2(){
  51.         return $this->gaveta2;
  52.     }
  53.     public function setGaveta2($g2){
  54.         $this->gaveta2=$g2;
  55.     }
  56.     public function getGaveta3(){
  57.         return $this->gaveta3;
  58.     }
  59.     public function setGaveta3($g3){
  60.         $this->gaveta3=$g3;
  61.     }
  62. }
  63.  
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement