Hi.
It makes sense a snippet like this:
<?php
class Builder{
public function __construct(){}
public function __get($nm){
return $this->{$nm};
}
public function __set($nm, $val){
$this->{$nm} = $val;
}
}
class Example{
//$items= $this->xp->query($query);
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() {
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."<br />";
}
?>
to emulate in such a way mysql_fetch_object ?
Bye.
It makes sense a snippet like this:
<?php
class Builder{
public function __construct(){}
public function __get($nm){
return $this->{$nm};
}
public function __set($nm, $val){
$this->{$nm} = $val;
}
}
class Example{
//$items= $this->xp->query($query);
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() {
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."<br />";
}
?>
to emulate in such a way mysql_fetch_object ?
Bye.