Meine Funktion, prepare(), hat die Definition:Warum funktioniert das Übergeben einer Variablen als Verweis nicht, wenn eine reflektive Methode aufgerufen wird?
private Funktion vorbereiten (& $ data, $ Bedingungen = null, $ conditionsRequired = false)
Als ich es testen, diese
/**
* @covers /data/DB_Service::prepare
* @uses /inc/config
*/
public function testNoExceptionIsRaisedForValidPrepareWithConditionsAndConditionsRequiredArguments() {
$method = new ReflectionMethod('DB_Service', 'prepare');
$method->setAccessible(TRUE);
$dbs = new DB_Service(new Config(), array('admin', 'etl'));
$data = array('message' => '', 'sql' => array('full_query' => ""));
$method->invoke($dbs, $data, array('conditionKey' => 'conditionValue'), TRUE);
}
Raises (und bricht mein Test)
Reflection: Invocation der Methode DB_Service :: prepare() fehlgeschlagen
Doch diese
/**
* @covers /data/DB_Service::prepare
* @uses /inc/config
*/
public function testNoExceptionIsRaisedForValidPrepareWithConditionsAndConditionsRequiredArguments() {
$method = new ReflectionMethod('DB_Service', 'prepare');
$method->setAccessible(TRUE);
$dbs = new DB_Service(new Config(), array('admin', 'etl'));
//$data is no longer declared - the array is directly in the call below
$method->invoke($dbs, array('message' => '', 'sql' => array('full_query' => "")), array('conditionKey' => 'conditionValue'), TRUE);
}
funktioniert perfekt und der Test erfolgreich ist.
Warum funktioniert das Deklarieren der Variablen und das Übergeben von nicht funktionieren, aber einfach das Erstellen in dem Methodenaufruf funktioniert? Ich denke, das hat etwas damit zu tun, wie invoke() funktioniert, aber ich kann nicht herausfinden, was.
Pro [dieser SO-Post] (http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available) ist dies veraltet in PHP5 und es wird abgeraten. In der Methodendefinition übergebe ich das Argument als Referenz, also sollte es im Aufruf nicht korrekt sein. –
@MatthewHerbst Du hast absolut Recht, mein Fehler. – wavemode
Ah, das InvokeArgs ist großartig. Vielen Dank! –