Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class A
  2. {
  3. private $name;
  4.  
  5. public function __construct()
  6. {
  7. $this->name = 'Some Name';
  8. }
  9.  
  10. public function getName()
  11. {
  12. return $this->name;
  13. }
  14. }
  15.  
  16. class B
  17. {
  18. private $a;
  19.  
  20. public function __construct(A $a)
  21. {
  22. $this->a = $a;
  23. }
  24.  
  25. function getNameOfA()
  26. {
  27. return $this->a->getName();
  28. }
  29. }
  30.  
  31. $a = new A();
  32. $b = new B($a);
  33.  
  34. $b->getNameOfA();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement