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 runNowUsingThis ParticularObjec tAndArray() 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 runNowUsingThis ParticularObjec tAndArray(&$act ionObject=false ,
&$getterObject= false) {
if (is_object($act ionObject) && is_object($gett erObject)) {
$countOfItemsTo LoopThrough = $selectObject->getCountOfRetu rn();
if (0 < $countOfItemsTo LoopThrough) {
$actionObject->beforeLoopStar ts();
for ($i=0; $i < $countOfItemsTo LoopThrough; $i++) {
$entry = $getterObject->getRowAsArrayW ithStringIndex( );
if ($i) $actionObject->betweenEachLoo p($i);
$actionObject->duringEachLoop ($entry, $i);
}
$actionObject->afterEachLoop( );
return $i;
}
} else {
if (is_object($act ionObject))
$this->resultsObjec t->addToErrorResu lts("In
runNowUsingThis ParticularObjec tAndArray(), in the class McLoop, we
expected the first parameter, actionObject, to be an object, but
instead we got this: $actionObject ");
if (is_object($get terObject))
$this->resultsObjec t->addToErrorResu lts("In
runNowUsingThis ParticularObjec tAndArray(), 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 ");
}
}
}
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 runNowUsingThis ParticularObjec tAndArray() 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 runNowUsingThis ParticularObjec tAndArray(&$act ionObject=false ,
&$getterObject= false) {
if (is_object($act ionObject) && is_object($gett erObject)) {
$countOfItemsTo LoopThrough = $selectObject->getCountOfRetu rn();
if (0 < $countOfItemsTo LoopThrough) {
$actionObject->beforeLoopStar ts();
for ($i=0; $i < $countOfItemsTo LoopThrough; $i++) {
$entry = $getterObject->getRowAsArrayW ithStringIndex( );
if ($i) $actionObject->betweenEachLoo p($i);
$actionObject->duringEachLoop ($entry, $i);
}
$actionObject->afterEachLoop( );
return $i;
}
} else {
if (is_object($act ionObject))
$this->resultsObjec t->addToErrorResu lts("In
runNowUsingThis ParticularObjec tAndArray(), in the class McLoop, we
expected the first parameter, actionObject, to be an object, but
instead we got this: $actionObject ");
if (is_object($get terObject))
$this->resultsObjec t->addToErrorResu lts("In
runNowUsingThis ParticularObjec tAndArray(), 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 ");
}
}
}
Comment