Hi there. I'm trying to implement something that should work like a VO design pattern. So I created 2 classes, one for the VO itself, and other that's gonna use this object by composition: here'r my codes :
class boxVO{
var $descricao;
var $parentID;
var $ID;
function boxVO(){
$this->parentID = $this->setParentID(0);
$this->descricao = $this->setDescricao("");
$this->ID = $this->setID(0);
}
function getDescricao(){
return $this->descricao;
}
function getID(){
return $this->ID;
}
function getParentID(){
return $this->parentID;
}
function setDescricao($desc){
$this->descricao = $desc;
}
function setParentID($PID){
$this->parentID = $PID;
}
function setID($ID) {
$this->ID = $ID;
}
}
class boxCollection {
var $database;
var $PID;
var $collection = array();
function boxCollection($db,$PID){
$this->database = $db;
$this->PID = $PID;
$this->populate();
}
function populate(){
$query = sprintf("SELECT no, descricao, parentField FROM %s.crmHistory WHERE parentField = %d",
$this->database,$this->PID);
$rs = mysql_query($query);
$i = 0;
while($row = mysql_fetch_object($rs)){
$collection[$i] = new boxVO();
$collection[$i]->setID($row->no);
$collection[$i]->setParentID($row->parentField);
$collection[$i]->setDescricao($row->descricao);
$i++;
}
}
}
Well, so far so good it seems that the collection array contains objects of VO type right?
But when I try to :
$box = new boxCollection("sqldados",1);
and then $box->collection[0]->getID();
it returns an error:
Fatal error: Call to a member function on a non-object in /home/vinicius/html/php/webcrm/testeBox.php on line 80
wha intrigates me, is that when calling the set methods it did not complain.
any ideas?
Thanks