Put objects into an array and get them
Posted: Wed Nov 16, 2005 1:33 pm
I have a task: reading / writing xml and working with objects. The only open questions (simply formulated)
HawleyJR:Please use tags when Posting PHP Code In The Forums
Code: Select all
<?php
class Woman{
private $id; // string
private $hair;
function getId(){return $this->id;}
}
class Man{
private $id; // string
private $car;
function getId(){return $this->id;}
}
class Group {
private $name;
private $members = array(); // array of classes woman / man
public function addMember ($member){
// how to add a new member with her - his id ?
$this->members[$member->id] = $member; // does not work
}
}
class World {
private $group; // Typ class Group
private $id;
private $test_id;
private $test_member; // woman - man
public function doit(){
$this->test_member = $this->group->members[$this->id]; // how to access a member ?
$this->test_id= $this->group->members[$this->id]->getId(); // how to access their methods ?
}
}
?>