fork download
  1. <?php
  2. class Root {
  3.  
  4. public $domainList = array();
  5.  
  6. public function addDomain($domainName)
  7. {
  8. $domain = new Domain($domainName);
  9. $this->domainList[$domainName] = $domain;
  10. }
  11.  
  12. public function getDomain($domainName)
  13. {
  14. return $this->domainList[$domainName];
  15. }
  16. }
  17.  
  18. class Domain {
  19.  
  20. public $domainName = null;
  21. public $memberList = array();
  22.  
  23. public function __construct($domainName) {
  24. $this->domainName = $domainName;
  25. }
  26.  
  27. public function addMember($email, $orders, $value) {
  28. $member = new Member($this->domainName, $email, $orders, $value);
  29. $this->memberList[$email] = $member;
  30. }
  31.  
  32. public function getMember($memberName) {
  33. return $this->memberList[$memberName];
  34. }
  35. }
  36.  
  37. class Member {
  38.  
  39. public $domain = null;
  40. public $email = null;
  41. public $orders = null;
  42. public $value = null;
  43.  
  44. public function __construct($domain, $email, $orders, $value) {
  45. $this->domain = $domain;
  46. $this->email = $email;
  47. $this->orders = $orders;
  48. $this->value = $value;
  49. }
  50.  
  51. public function getDomain() {
  52. return $this->domain;
  53. }
  54.  
  55. }
  56.  
  57. $root = new Root();
  58.  
  59. $root->addDomain("hotmail.com");
  60. $root->addDomain("gmail.com");
  61. $root->domainList["hotmail.com"]->addMember("john.doe",1,12);
  62. $root->domainList["hotmail.com"]->addMember("jessie.anderson",1,12);
  63. $root->domainList["hotmail.com"]->addMember("paul.whitney",1,12);
  64. $root->domainList["gmail.com"]->addMember("alexis",1,12);
  65.  
  66. print_r($root->domainList["hotmail.com"]->getMember("john.doe"));
  67. print_r($root->getDomain["hotmail.com"]);
  68. ?>
Success #stdin #stdout #stderr 0.02s 52432KB
stdin
Standard input is empty
stdout
Member Object
(
    [domain] => hotmail.com
    [email] => john.doe
    [orders] => 1
    [value] => 12
)
stderr
PHP Notice:  Undefined property: Root::$getDomain in /home/T43KGR/prog.php on line 67