Ignore:
Timestamp:
May 3, 2014 3:13:19 PM (10 years ago)
Author:
anonymous
Message:

Added cookie storage to Prefs(). Created App->addCookie method. Improved PHP version checks.

File:
1 edited

Legend:

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

    r474 r477  
    2929 * Print variable dump.
    3030 *
    31  * @param  mixed $var      Variable to dump.
    32  * @param  bool  $display   Hide the dump in HTML comments?
    33  * @param  bool  $var_dump Use var_dump instead of print_r.
     31 * @param  mixed    $var        The variable to dump.
     32 * @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.
     34 * @param  string   $file       Value of __FILE__.
     35 * @param  string   $line       Value of __LINE__
    3436 */
    3537function dump($var, $display=false, $var_dump=false, $file='', $line='')
    3638{
    37     if (empty($var)) {
    38         $var = '(nothing to dump)';
    39     }
    4039    if (defined('_CLI')) {
    41         echo "\nDUMP FROM: $file $line\n";
    42     } else {
    43         echo $display ? "\n<br />DUMP: <strong>$file $line</strong>\n<br /><pre>\n" : "\n\n\n<!--\n$file $line\n";
     40        echo "DUMP FROM: $file $line\n";
     41    } else {
     42        echo $display ? "\n<br />DUMP <strong>$file $line</strong><br /><pre>\n" : "\n<!-- DUMP $file $line\n";
    4443    }
    4544    if ($var_dump) {
    4645        var_dump($var);
    4746    } else {
    48         print_r($var);
     47        // Print human-readable descriptions of invisible types.
     48        if (null === $var) {
     49            echo '(null)';
     50        } else if (true === $var) {
     51            echo '(bool: true)';
     52        } else if (false === $var) {
     53            echo '(bool: false)';
     54        } else if (is_scalar($var) && '' === $var) {
     55            echo '(empty string)';
     56        } else if (is_scalar($var) && preg_match('/^\s+$/', $var)) {
     57            echo '(only white space)';
     58        } else {
     59            print_r($var);
     60        }
    4961    }
    5062    if (defined('_CLI')) {
    5163        echo "\n";
    5264    } else {
    53         echo $display ?  "\n</pre><br />\n" : "\n-->\n\n\n";
     65        echo $display ? "\n</pre><br />\n" : "\n-->\n";
    5466    }
    5567}
Note: See TracChangeset for help on using the changeset viewer.