couple methods:
1) create an instance of the second class within the first:
PHP Code:
class Person{
public $name = 'Stefan';
public $city;
public function get_city(){
$cityclass = new City();
$this->city = $cityclass->get_city();
return $this->city;
}
}
2) create an instance of the second class outside the first:
PHP Code:
$cityclass = new City();
$city = $cityclass->get_city();
class Person{
public function get_persons_city(){
global $city;
return $city;
}
}
3) have the city class extend the person class:
PHP Code:
class City extends Person{
public $city='Springfield';
public function get_city(){
return $this->city();
}
public function get_name(){
return parent::get_name();
}
}
Bookmarks