dimanche 8 janvier 2017

passing by reference with reflection

http://ift.tt/2i4dVHn has the following method:

/**
 * Call protected/private method of a class.
 *
 * @param object &$object    Instantiated object that we will run method on.
 * @param string $methodName Method name to call
 * @param array  $parameters Array of parameters to pass into method.
 *
 * @return mixed Method return.
 */
public function invokeMethod(&$object, $methodName, array $parameters = array())
{
    $reflection = new \ReflectionClass(get_class($object));
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);

    return $method->invokeArgs($object, $parameters);
}

My question is... is there a particular reason why $object has an ampersand before it in the function declaration? Normally that'd mean you were passing by reference but doens't PHP pass objects by reference by default?





Aucun commentaire:

Enregistrer un commentaire