-
Notifications
You must be signed in to change notification settings - Fork 10
Cookbook: Inspecting a variable's value
MIK provides a utility function that dumps the contents of a variable. This function will be of use to developers and to general MIK users who need extra information to troubleshoot problems. The function's signature is:
/**
* Utility function to dump a variable to a log.
*
* @param $variable mixed
* The variable to dump.
* @param $label string
* A label to dump along with the value. Defaults to ''.
* @param $dest string
* The full path to a log file. Defaults to the system's
* temp directory with a filename of 'mik_dumper.txt'.
*/
function dump($variable, $label = null, $dest = null) {}
The default directory of the destination output file is determined by PHP's sys_get_temp_dir function, usually "/tmp" on Linux and OSX systems and "C:\Windows\Temp" on Windows systems.
To use this utility function, instantiate a new Dumper object and then call its dump
method:
$dumper = new \mik\utilities\Dumper();
$dumper->dump($record, 'Record', '/tmp/foo.txt');
In this example, the value of the variable $record
is dumped to the file /tmp/foo.txt
, prepended with the label Record
. The output file will contain the value of each instance of the $record variable:
Record:
stdClass::__set_state(array(
'Identifier' => 'image01',
'File' => 'IMG_1410.JPG',
'Title' => 'Small boats in Havana Harbour',
'Date taken' => '2015-03-08',
'Subjects' => 'Boats; water',
'Note' => 'Taken on vacation in Cuba.',
'key' => 'image01',
))
Content on the Move to Islandora Kit wiki is licensed under a Creative Commons Attribution 4.0 International License.