Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. class pai {
  4. public $filha;
  5.  
  6.  
  7. public function setFilha($class) {
  8. $this->filha = $class;
  9. }
  10.  
  11.  
  12. }
  13.  
  14. class filha {
  15. public function dizerOi() {
  16. echo 'oi';
  17. }
  18. }
  19.  
  20.  
  21. // Instancia a classe Pai
  22. $pai = new pai();
  23.  
  24. // Instancia a classe filha
  25. $filha = new filha();
  26.  
  27.  
  28. //Passa a classe filha a classe pai.
  29. $pai->setFilha($filha);
  30.  
  31.  
  32. // Executa o metodo da classe filha, que está agora dentro da classe pai
  33. $pai->filha->dizerOi();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement