bug #1525393, no page selector in foreign key browse page
[phpmyadmin/last10db.git] / libraries / compat / var_export.php
blob613b0ccdff8c2cfe9f6a8edc5ba1008d2fda19b0
1 <?php
2 // +----------------------------------------------------------------------+
3 // | PHP Version 4 |
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1997-2004 The PHP Group |
6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 3.0 of the PHP license, |
8 // | that is bundled with this package in the file LICENSE, and is |
9 // | available at through the world-wide-web at |
10 // | http://www.php.net/license/3_0.txt. |
11 // | If you did not receive a copy of the PHP license and are unable to |
12 // | obtain it through the world-wide-web, please send a note to |
13 // | license@php.net so we can mail you a copy immediately. |
14 // +----------------------------------------------------------------------+
15 // | Authors: Aidan Lister <aidan@php.net> |
16 // +----------------------------------------------------------------------+
18 // $Id: var_export.php,v 1.18 2006/05/22 00:09:42 arpad Exp $
21 /**
22 * Replace var_export()
24 * @category PHP
25 * @package PHP_Compat
26 * @link http://php.net/function.var_export
27 * @author Aidan Lister <aidan@php.net>
28 * @version $Revision: 1.18 $
29 * @since PHP 4.2.0
30 * @require PHP 4.0.0 (user_error)
32 function php_compat_var_export($var, $return = false, $level = 0, $inObject = false)
34 // Init
35 $indent = ' ';
36 $doublearrow = ' => ';
37 $lineend = ",\n";
38 $stringdelim = '\'';
39 $newline = "\n";
40 $find = array(null, '\\', '\'');
41 $replace = array('NULL', '\\\\', '\\\'');
42 $out = '';
44 // Indent
45 $level++;
46 for ($i = 1, $previndent = ''; $i < $level; $i++) {
47 $previndent .= $indent;
50 $varType = gettype($var);
52 // Handle object indentation oddity
53 if ($inObject && $varType != 'object') {
54 $previndent = substr($previndent, 0, -1);
58 // Handle each type
59 switch ($varType) {
60 // Array
61 case 'array':
62 if ($inObject) {
63 $out .= $newline . $previndent;
65 $out .= 'array (' . $newline;
66 foreach ($var as $key => $value) {
67 // Key
68 if (is_string($key)) {
69 // Make key safe
70 $key = str_replace($find, $replace, $key);
71 $key = $stringdelim . $key . $stringdelim;
74 // Value
75 if (is_array($value)) {
76 $export = php_compat_var_export($value, true, $level);
77 $value = $newline . $previndent . $indent . $export;
78 } else {
79 $value = php_compat_var_export($value, true, $level);
82 // Piece line together
83 $out .= $previndent . $indent . $key . $doublearrow . $value . $lineend;
86 // End string
87 $out .= $previndent . ')';
88 break;
90 // String
91 case 'string':
92 // Make the string safe
93 for ($i = 0, $c = count($find); $i < $c; $i++) {
94 $var = str_replace($find[$i], $replace[$i], $var);
96 $out = $stringdelim . $var . $stringdelim;
97 break;
99 // Number
100 case 'integer':
101 case 'double':
102 $out = (string) $var;
103 break;
105 // Boolean
106 case 'boolean':
107 $out = $var ? 'true' : 'false';
108 break;
110 // NULLs
111 case 'NULL':
112 case 'resource':
113 $out = 'NULL';
114 break;
116 // Objects
117 case 'object':
118 // Start the object export
119 $out = $newline . $previndent;
120 $out .= get_class($var) . '::__set_state(array(' . $newline;
121 // Export the object vars
122 foreach(get_object_vars($var) as $key => $value) {
123 $out .= $previndent . $indent . ' ' . $stringdelim . $key . $stringdelim . $doublearrow;
124 $out .= php_compat_var_export($value, true, $level, true) . $lineend;
126 $out .= $previndent . '))';
127 break;
130 // Method of output
131 if ($return === true) {
132 return $out;
133 } else {
134 echo $out;
139 // Define
140 if (!function_exists('var_export')) {
141 function var_export($var, $return = false)
143 return php_compat_var_export($var, $return);