Created
September 4, 2013 11:04
-
-
Save Arakaki/6435577 to your computer and use it in GitHub Desktop.
varToString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function varToString($var) | |
{ | |
if (is_object($var)) { | |
return sprintf('Object(%s)', get_class($var)); | |
} | |
if (is_array($var)) { | |
$a = array(); | |
foreach ($var as $k => $v) { | |
$a[] = sprintf('%s => %s', $k, $this->varToString($v)); | |
} | |
return sprintf("Array(%s)", implode(', ', $a)); | |
} | |
if (is_resource($var)) { | |
return sprintf('Resource(%s)', get_resource_type($var)); | |
} | |
if (null === $var) { | |
return 'null'; | |
} | |
if (false === $var) { | |
return 'false'; | |
} | |
if (true === $var) { | |
return 'true'; | |
} | |
return (string) $var; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment