fork download
  1. <?php
  2.  
  3. class Setor {
  4.  
  5. private $descricaoCat;
  6. private $codigo;
  7.  
  8. function getCodigo() {
  9. return $this->codigo;
  10. }
  11.  
  12. function getDescricaoCat() {
  13. return $this->descricaoCat;
  14. }
  15.  
  16. function setCodigo($codigo){
  17. $this->codigo = $codigo;
  18. }
  19.  
  20. function setDescricaoCat($descricaoCat) {
  21. $this->descricaoCat = $descricaoCat;
  22. }
  23. }
  24.  
  25. class Produto {
  26.  
  27. private $descP;
  28. private $qtdP;
  29. private $unitarioP;
  30. private $Setor; //ReferĂȘncia para Pegar Atributos e Metodos da Classe Setor.
  31.  
  32. function __construct() {
  33.  
  34. $this->Setor = new Setor();
  35. }
  36.  
  37. function getDescP() {
  38. return $this->descP;
  39. }
  40.  
  41. function getQtdP() {
  42. return $this->qtdP;
  43. }
  44.  
  45. function getUnitarioP() {
  46. return $this->unitarioP;
  47. }
  48.  
  49. function getSetor() {
  50. return $this->Setor;
  51. }
  52.  
  53. function setDescP($descP) {
  54. $this->descP = $descP;
  55. }
  56.  
  57. function setQtdP($qtdP) {
  58. $this->qtdP = $qtdP;
  59. }
  60.  
  61. function setUnitarioP($unitarioP) {
  62. $this->unitarioP = $unitarioP;
  63. }
  64.  
  65. function setSetor($Setor) {
  66. $this->Setor = $Setor;
  67. }
  68. }
  69.  
  70. $setor = new Setor();
  71. $setor->setCodigo(171);
  72. $setor->setDescricaoCat("MASSAS");
  73.  
  74. $produto = new Produto();
  75. $produto->setDescP("Coca-Cola Light 3L");
  76. $produto->setQtdP(20);
  77. $produto->setUnitarioP(5.89);
  78. $produto->setSetor($setor);
  79.  
  80.  
  81. echo $produto->getSetor()->getDescricaoCat();
Success #stdin #stdout 0.01s 82560KB
stdin
Standard input is empty
stdout
    MASSAS