Changeset 613


Ignore:
Timestamp:
Oct 3, 2017 7:16:47 AM (7 years ago)
Author:
anonymous
Message:

Add dump_method to function dump()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r609 r613  
    3131 * @param  mixed    $var        The variable to dump.
    3232 * @param  bool     $display    Print the dump in <pre> tags or hide it in html comments (non-CLI only).
    33  * @param  bool     $var_dump   Use var_dump instead of print_r.
     33 * @param  bool     $dump_method   Dump method. See SC_DUMP_* constants.
    3434 * @param  string   $file       Value of __FILE__.
    3535 * @param  string   $line       Value of __LINE__
    3636 */
    37 function dump($var, $display=false, $var_dump=false, $file='', $line='')
     37define('SC_DUMP_PRINT_R', 0);
     38define('SC_DUMP_VAR_DUMP', 1);
     39define('SC_DUMP_VAR_EXPORT', 2);
     40function dump($var, $display=false, $dump_method=SC_DUMP_PRINT_R, $file='', $line='')
    3841{
    3942    $app =& App::getInstance();
     
    4447        echo $display ? "\n<br />DUMP <strong>$file $line</strong><br /><pre>\n" : "\n<!-- DUMP $file $line\n";
    4548    }
    46     if ($var_dump) {
    47         var_dump($var);
    48     } else {
     49
     50    switch ($dump_method) {
     51    case SC_DUMP_PRINT_R:
     52    default:
    4953        // Print human-readable descriptions of invisible types.
    5054        if (null === $var) {
     
    6165            print_r($var);
    6266        }
    63     }
     67        break;
     68
     69    case SC_DUMP_VAR_DUMP:
     70        var_dump($var);
     71        break;
     72
     73    case SC_DUMP_VAR_EXPORT:
     74        var_export($var);
     75        break;
     76    }
     77
    6478    if ($app->cli) {
    6579        echo "\n";
Note: See TracChangeset for help on using the changeset viewer.