The following class method is being rejected by the PHP parser. If I
change the method paramaters and allow the objects to be passed as
copies, then the parser has no problem. Or, if I pass by reference but
set no default value, then the parser has no problems. I've resovled
this for now by taking out the "false" default values. But how shall I
handle those situations (there are many) where I wish to pass an
object by reference but I'm not sure I'll be passing one?
In short, how does one get non-mandatory function parameters to pass
by reference?
/**
* 12-28-03 - manipulator
*
* We want to go over a data set and commit a bunch of actions on the
data in that set. For instance, the class McShow uses
* a getterObject to get data from the datastore, which is then passed
into this method, and McShow also passes in an htmlObject
* as the action object, which takes the data given by the
getterObject and wraps in HTML and outputs it to the screen.
*
*
* @param - $actionObject - object - this is an object that has the 4
methods that are going to be called from within the loop. An
* example would be all the Html objects. The class McShow, for
instance, calls McLoop in its (McShow's) printToScreen() method,
* wherein it invokes runNowUsingThisParticularObjectAndArray() and
hands it an htmlObject as the first parameter.
*
* @param - $getterObject - object - this is going to be an object
that knows how to get data out of some data store, be it an array,
* the file system, or a database.
*
* 02-28-04 - PHP isn't letting me pass objects by reference and give
them a false default value
*
* public
* returns integer - number of times the loop iterated.
*/
function runNowUsingThisParticularObjectAndArray(&$actionOb ject=false,
&$getterObject=false) {
if (is_object($actionObject) && is_object($getterObject)) {
$countOfItemsToLoopThrough = $selectObject->getCountOfReturn();
if (0 < $countOfItemsToLoopThrough) {
$actionObject->beforeLoopStarts();
for ($i=0; $i < $countOfItemsToLoopThrough; $i++) {
$entry = $getterObject->getRowAsArrayWithStringIndex();
if ($i) $actionObject->betweenEachLoop($i);
$actionObject->duringEachLoop($entry, $i);
}
$actionObject->afterEachLoop();
return $i;
}
} else {
if (is_object($actionObject))
$this->resultsObject->addToErrorResults("In
runNowUsingThisParticularObjectAndArray(), in the class McLoop, we
expected the first parameter, actionObject, to be an object, but
instead we got this: $actionObject ");
if (is_object($getterObject))
$this->resultsObject->addToErrorResults("In
runNowUsingThisParticularObjectAndArray(), in the class McLoop, we
were expecting the second parameter to be an object for getting data
from a datastore, but instead we got this: $getterObject ");
}
}
}