update var_export to currect CVS
This commit is contained in:
@@ -6,6 +6,9 @@ $Id$
|
|||||||
$Source$
|
$Source$
|
||||||
|
|
||||||
|
|
||||||
|
2006-07-19 Michal Čihař <michal@cihar.com>
|
||||||
|
* libraries/compat/var_export.php: Update to fixed version.
|
||||||
|
|
||||||
2006-07-19 Sebastian Mendel <cybot_tm@users.sourceforge.net>
|
2006-07-19 Sebastian Mendel <cybot_tm@users.sourceforge.net>
|
||||||
* lang/german: updated, typos
|
* lang/german: updated, typos
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
// | Authors: Aidan Lister <aidan@php.net> |
|
// | Authors: Aidan Lister <aidan@php.net> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: var_export.php,v 1.15 2005/12/05 14:24:27 aidan Exp $
|
// $Id: var_export.php,v 1.18 2006/05/22 00:09:42 arpad Exp $
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,12 +25,11 @@
|
|||||||
* @package PHP_Compat
|
* @package PHP_Compat
|
||||||
* @link http://php.net/function.var_export
|
* @link http://php.net/function.var_export
|
||||||
* @author Aidan Lister <aidan@php.net>
|
* @author Aidan Lister <aidan@php.net>
|
||||||
* @version $Revision: 1.15 $
|
* @version $Revision: 1.18 $
|
||||||
* @since PHP 4.2.0
|
* @since PHP 4.2.0
|
||||||
* @require PHP 4.0.0 (user_error)
|
* @require PHP 4.0.0 (user_error)
|
||||||
*/
|
*/
|
||||||
if (!function_exists('var_export')) {
|
function php_compat_var_export($var, $return = false, $level = 0, $inObject = false)
|
||||||
function var_export($var, $return = false, $level = 0)
|
|
||||||
{
|
{
|
||||||
// Init
|
// Init
|
||||||
$indent = ' ';
|
$indent = ' ';
|
||||||
@@ -48,27 +47,36 @@ if (!function_exists('var_export')) {
|
|||||||
$previndent .= $indent;
|
$previndent .= $indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$varType = gettype($var);
|
||||||
|
|
||||||
|
// Handle object indentation oddity
|
||||||
|
if ($inObject && $varType != 'object') {
|
||||||
|
$previndent = substr($previndent, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle each type
|
// Handle each type
|
||||||
switch (gettype($var)) {
|
switch ($varType) {
|
||||||
// Array
|
// Array
|
||||||
case 'array':
|
case 'array':
|
||||||
$out = 'array (' . $newline;
|
if ($inObject) {
|
||||||
|
$out .= $newline . $previndent;
|
||||||
|
}
|
||||||
|
$out .= 'array (' . $newline;
|
||||||
foreach ($var as $key => $value) {
|
foreach ($var as $key => $value) {
|
||||||
// Key
|
// Key
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
// Make key safe
|
// Make key safe
|
||||||
for ($i = 0, $c = count($find); $i < $c; $i++) {
|
$key = str_replace($find, $replace, $key);
|
||||||
$var = str_replace($find[$i], $replace[$i], $var);
|
|
||||||
}
|
|
||||||
$key = $stringdelim . $key . $stringdelim;
|
$key = $stringdelim . $key . $stringdelim;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value
|
// Value
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$export = var_export($value, true, $level);
|
$export = php_compat_var_export($value, true, $level);
|
||||||
$value = $newline . $previndent . $indent . $export;
|
$value = $newline . $previndent . $indent . $export;
|
||||||
} else {
|
} else {
|
||||||
$value = var_export($value, true, $level);
|
$value = php_compat_var_export($value, true, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Piece line together
|
// Piece line together
|
||||||
@@ -108,19 +116,14 @@ if (!function_exists('var_export')) {
|
|||||||
// Objects
|
// Objects
|
||||||
case 'object':
|
case 'object':
|
||||||
// Start the object export
|
// Start the object export
|
||||||
$out = $newline . $previndent . 'class ' . get_class($var) . ' {' . $newline;
|
$out = $newline . $previndent;
|
||||||
|
$out .= get_class($var) . '::__set_state(array(' . $newline;
|
||||||
// Export the object vars
|
// Export the object vars
|
||||||
foreach (get_object_vars($var) as $key => $val) {
|
foreach(get_object_vars($var) as $key => $value) {
|
||||||
$out .= $previndent . ' var $' . $key . ' = ';
|
$out .= $previndent . $indent . ' ' . $stringdelim . $key . $stringdelim . $doublearrow;
|
||||||
if (is_array($val)) {
|
$out .= php_compat_var_export($value, true, $level, true) . $lineend;
|
||||||
$export = var_export($val, true, $level);
|
|
||||||
$out .= $newline . $previndent . $indent . $export . ';' . $newline;
|
|
||||||
} else {
|
|
||||||
$out .= var_export($val, true, $level) . ';' . $newline;
|
|
||||||
}
|
}
|
||||||
}
|
$out .= $previndent . '))';
|
||||||
$out .= $previndent . '}';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +134,12 @@ if (!function_exists('var_export')) {
|
|||||||
echo $out;
|
echo $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
// Define
|
||||||
|
if (!function_exists('var_export')) {
|
||||||
|
function var_export($var, $return = false)
|
||||||
|
{
|
||||||
|
return php_compat_var_export($var, $return);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user