Using an aggregated class : Class Definition « Class « PHP






Using an aggregated class

 
<?
class Address { 
  protected $city;
  protected $country;
 
  public function setCity($city) { $this->city = $city; }
  public function getCity() { return $this->city; } 
  public function setCountry($country) { $this->country = $country; }
  public function getCountry() { return $this-> country;}
}

class Person {
 protected $name;
 protected $address;

 public function __construct() { $this->address = new Address; }
 public function setName($name) { $this->name = $name; }
 public function getName() { return $this->name; }
 public function __call($method, $arguments) { 
  if (method_exists($this->address, $method)) { 
   return call_user_func_array( array($this->address, $method), $arguments);
  }
 }
}
?>
  
  








Related examples in the same category

1.A Basic PHP 4 Class
2.A Basic PHP 5 Class
3.A class is a collection of variables and functions working with these variables.
4.Aggregating an address object
5.Bird class
6.Basic Object Accessing
7.Class Type Hints
8.Implementing a Simple Class
9.Person class
10.PHP class declaration structure
11.book class
12.Pre-defined methods
13.Empty class