Ciao.
Secondo voi è un metodo valido
per emulare mysql_fetch_object:
Codice PHP:
<?php
class Builder{
public function __construct(){}
public function __get($nm){
return $this->{$nm};
}
public function __set($nm, $val){
$this->{$nm} = $val;
}
}
class Example{
public $items = array(array("id" => 1, "title" => "One", "content" => "Bla bla one"),array("id" => 1, "title" => "Two", "content" => "Bla bla two"));
public $b=array();
function setObjects() {
//Quando recupero il nome del tag e il suo valore facendo il parsing di un xml file
//farei una cosa del genere
foreach($this->items as $value){
$builder= new Builder();
foreach($value as $key => $v){
$builder->{$key}= $v;
}
$this->b[]=$builder;
unset($builder);
}
}
function fetchObject(){
if($obj=array_shift($this->b)){
return $obj;
}
else{
return false;
}
}
}
$class = new Example();
$class->setObjects();
while($obj = $class->fetchObject()){
echo $obj->id."-".$obj->title."-".$obj->content."
";
}
?>