how does one get non-mandatory function parameters to pass by reference?

From: lawrence (lkrubner_at_geocities.com)
Date: 02/28/04


Date: 28 Feb 2004 09:41:14 -0800

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(&$actionObject=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 ");
                }
        }
}



Relevant Pages

  • Re: Named regexp variables, an extension proposal.
    ... John Machin wrote: ... reference the literal contents of groups appearing after the variable ... Regex syntax is over-rich already. ... complete parser for Verilog, I want to take an easier 'good enough' ...
    (comp.lang.python)
  • modify instance variable in a method mixed in from external module
    ... I have this gem of a parser that does: ... def parse_data data ... Why can't we have something like C++ reference, ... calling method, changes will be lost. ...
    (comp.lang.ruby)
  • Re: Disposing of an object?
    ... If the instance of XMLParser 'parser' is still hanging around and a new instance also called 'parser' is created how will it know which 'parser' to reference? ... named 'parser' and initialized with a pointer to a new XMLParser". ...
    (comp.lang.java.programmer)
  • Re: What this mean for Borland?
    ... marc hoffman wrote in message ... /my/ parser cannot find any reference to RemObjects in my ... Posted with JSNewsreader Preview 0.9.4.2216 ...
    (borland.public.delphi.non-technical)