You all got me wrong

Yes, I was doing crazy things. But I solved it just after I posted yesterday.
I posted in the General Discussion because I was not asking for help.
Here's how it works now:
Code: Select all
<?php
/*
@descr: Handles looping through an array;
*/
class iterator{
var $arrResultSet = array();
var $intIndex = 0;
var $element = null;
/**
* @return void
* @param $array array
* @desc Moves index forward $intSteps steps if positive, backwards if negative.
*/
function setResultSet( $array){
$this->arrResultSet = $array;
$this->intIndex = 0;
}
function reset(){
$this->intIndex = 0;
}
/**
* @return mixed
* @desc Fetches current element in array then moves index forward.
Returns false when no elements are left to fetch.
*/
function fetchNextElement(){
if (isset($this->arrResultSet[$this->intIndex])){
$this->element = & $this->arrResultSet[$this->intIndex];
$this->intIndex++;
return true;
}else{
$this->reset();
return false;
}
}
/**
* @return void
* @param $intSteps integer
* @desc Moves index forward $intSteps steps if positive, backwards if negative.
*/
function moveIndex($intSteps){
$this->intIndex += $intSteps;
}
function getIndex(){
return $this->intIndex ;
}
/**
* @return unknown
* @desc returns currently fetched element.
*/
function & getElement(){
return $this->element;
}
function & getAllElements(){
return $this->arrResultSet;
}
}
?>
I wanted a way to do this:
Code: Select all
<?php
//$this is of class article that has inherited the iterator class.
while($this->fetchNextElement()){
$arrArticle = & $this->getElement();
$arrArticle['strDate'] = date('Y-m-d H:i', $arrArticle['intTimeStamp']);
}
?>
It works just as intended because of the reference passing all over the place.
I shot myself in my foot while setting this up and was surprised, because I had never seen this error msg before.
Even more fun, was that I was only pulling like 100 bytes out of mysql while getting an 8MB memory limit fatal error
I didn't really need help this time, but I'd like to say thanks to volka anyway, because he/she has been of unmatched help before when I've been in trouble.
Cheers.