I am quite new to PHP but am making good progress.
One problem I have is understanding how to access one class from another.
As an example I have created two classes
PHP Code:
class address{
private $addressline1;
private $addressline2;
private $suburb;
etc...
function __constructor(params){
code....;
}
function set_value($param){
code...;
}
function get_address(){
echo $this->addressline1."\n";
}
} //End class Address
class person{
private $firstname;
private $lastname;
private $residential_address;
private $postal_address;
etc...
function __constructor(params){
code....;
}
function set_value($param){
code...;
}
function get_person(){
echo $this->firstname . " " . $this->lastname."\n";
etc....
}
Public function set_residential_address(address $a){
$this->residential_address = $a;
}
} //End class person
When I use these two classes I am doing the following
PHP Code:
$mark = new person('Mark','1234556','03-Jul-1964');
$new_address = new address('Magnolia cottage','',8,'Margaret','Street','Northmeade');
$new_address->get_address();
$mark->set_residential_address($new_address);
My issue or problem is how do I display the individual address details.
What sort of class constructs do I need in the person class.
Or to display the details once I've assigned values and assigned the Person->Residential_address do I just use the
$new_address->get_address
I would think a well developed person or user class and address class would be usefel in
lots of applications.
thanks
Mark