summaryrefslogtreecommitdiff
path: root/pear/tests/php_dump.php.inc
diff options
context:
space:
mode:
Diffstat (limited to 'pear/tests/php_dump.php.inc')
-rw-r--r--pear/tests/php_dump.php.inc57
1 files changed, 57 insertions, 0 deletions
diff --git a/pear/tests/php_dump.php.inc b/pear/tests/php_dump.php.inc
new file mode 100644
index 000000000..4f7a66629
--- /dev/null
+++ b/pear/tests/php_dump.php.inc
@@ -0,0 +1,57 @@
+<?php
+class PHP_Dump {
+ var $_var;
+ function PHP_Dump($var)
+ {
+ $this->_var = $var;
+ }
+
+ function toPHP()
+ {
+ return $this->_toUnknown($this->_var);
+ }
+
+ function _toUnknown($var, $indent = ' ')
+ {
+ switch (gettype($var)) {
+ case 'array' :
+ return $this->_toArray($var, $indent);
+ case 'boolean' :
+ return $this->_toBool($var, $indent);
+ case 'double' :
+ case 'integer' :
+ return $this->_toNumber($var, $indent);
+ case 'NULL' :
+ return "{$indent}null";
+ case 'string' :
+ return $this->_toString($var, $indent);
+ }
+ }
+
+ function _toString($var, $indent)
+ {
+ return $indent . '"' . addslashes($var) . '"';
+ }
+
+ function _toBool($var, $indent)
+ {
+ return $indent . ($var ? 'true' : 'false');
+ }
+
+ function _toNumber($var, $indent)
+ {
+ return $indent . $var;
+ }
+
+ function _toArray($var, $indent = ' ')
+ {
+ $ret = $indent . "array(\n";
+ foreach ($var as $key => $value) {
+ $ret .= $indent . ((is_int($key) || is_double($key)) ? $key : "'$key'") . " =>\n";
+ $ret .= $this->_toUnknown($value, "$indent ") . ",\n";
+ }
+ $ret .= $indent . ')';
+ return $ret;
+ }
+}
+?> \ No newline at end of file