MDL-53430 dml: Fix recordset_walk for additional parameters

This commit is contained in:
Eric Merrill
2016-03-10 16:32:02 -05:00
parent e8952c5951
commit 208a79c920
2 changed files with 23 additions and 10 deletions
+6 -6
View File
@@ -57,7 +57,7 @@ class recordset_walk implements \Iterator {
protected $callback;
/**
* @var array|false Extra params for the callback.
* @var mixed|null Extra param for the callback.
*/
protected $callbackextra;
@@ -66,9 +66,9 @@ class recordset_walk implements \Iterator {
*
* @param \moodle_recordset $recordset Recordset to iterate.
* @param callable $callback Apply this function to each record. If using a method, it should be public.
* @param array $callbackextra Array of arguments to pass to the callback.
* @param mixed $callbackextra An extra single parameter to pass to the callback. Use a container to pass multiple values.
*/
public function __construct(\moodle_recordset $recordset, callable $callback, $callbackextra = false) {
public function __construct(\moodle_recordset $recordset, callable $callback, $callbackextra = null) {
$this->recordset = $recordset;
$this->callback = $callback;
$this->callbackextra = $callbackextra;
@@ -99,10 +99,10 @@ class recordset_walk implements \Iterator {
}
// Apply callback and return.
if ($this->callbackextra) {
return call_user_func($this->callback, $record);
} else {
if (!is_null($this->callbackextra)) {
return call_user_func($this->callback, $record, $this->callbackextra);
} else {
return call_user_func($this->callback, $record);
}
}