Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core\dml\recordset_walk Class Reference

Iterator that walks through a moodle_recordset applying the provided function. More...

Inheritance diagram for core\dml\recordset_walk:

Public Member Functions

 __construct (\moodle_recordset $recordset, callable $callback, $callbackextra=null)
 Create a new iterator applying the callback to each record.
 
 __destruct ()
 Closes the recordset.
 
 close ()
 Closes the recordset.
 
 current ()
 Returns the current element after applying the callback.
 
 key ()
 Returns current record key.
 
 next ()
 Moves the internal pointer to the next record.
 
 rewind ()
 Rewind is not supported.
 
 valid ()
 Returns whether the current position is valid or not.
 

Protected Attributes

callable $callback
 The callback.
 
mixed null $callbackextra
 Extra param for the callback.
 
moodle_recordset $recordset
 The recordset.
 

Detailed Description

Iterator that walks through a moodle_recordset applying the provided function.

The internal recordset can be closed using the close() function.

Note that consumers of this class are responsible of closing the recordset, although there are some implicit closes under some ciscumstances:

  • Once all recordset records have been iterated
  • The object is destroyed
Since
Moodle 2.9
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\dml\recordset_walk::__construct ( \moodle_recordset $recordset,
callable $callback,
$callbackextra = null )

Create a new iterator applying the callback to each record.

Parameters
moodle_recordset$recordsetRecordset to iterate.
callable$callbackApply this function to each record. If using a method, it should be public.
mixed$callbackextraAn extra single parameter to pass to the callback. Use a container to pass multiple values.

◆ __destruct()

core\dml\recordset_walk::__destruct ( )

Closes the recordset.

Return values
void

Member Function Documentation

◆ close()

core\dml\recordset_walk::close ( )

Closes the recordset.

Return values
void

◆ current()

core\dml\recordset_walk::current ( )

Returns the current element after applying the callback.

Return values
mixed|boolThe returned value type will depend on the callback.

◆ key()

core\dml\recordset_walk::key ( )

Returns current record key.

Return values
int

◆ next()

core\dml\recordset_walk::next ( )

Moves the internal pointer to the next record.

Return values
void

◆ rewind()

core\dml\recordset_walk::rewind ( )

Rewind is not supported.

Return values
void

◆ valid()

core\dml\recordset_walk::valid ( )

Returns whether the current position is valid or not.

If we reached the end of the recordset we close as we don't allow rewinds. Doing do so we reduce the chance of unclosed recordsets.

Return values
bool

The documentation for this class was generated from the following file: