Changeset 477 for trunk/lib/Utilities.inc.php
- Timestamp:
- May 3, 2014 3:13:19 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r474 r477 29 29 * Print variable dump. 30 30 * 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__ 34 36 */ 35 37 function dump($var, $display=false, $var_dump=false, $file='', $line='') 36 38 { 37 if (empty($var)) {38 $var = '(nothing to dump)';39 }40 39 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"; 44 43 } 45 44 if ($var_dump) { 46 45 var_dump($var); 47 46 } 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 } 49 61 } 50 62 if (defined('_CLI')) { 51 63 echo "\n"; 52 64 } else { 53 echo $display ? "\n</pre><br />\n" : "\n-->\n\n\n";65 echo $display ? "\n</pre><br />\n" : "\n-->\n"; 54 66 } 55 67 }
Note: See TracChangeset
for help on using the changeset viewer.