cvs: pear /PHP_Compat/Compat/Function var_export.php

From: Date: Mon, 28 Feb 2005 08:46:06 +0000
Subject: cvs: pear /PHP_Compat/Compat/Function var_export.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-29920@lists.php.net to get a copy of this message
aidan Mon Feb 28 03:46:06 2005 EDT Modified files: /pear/PHP_Compat/Compat/Function var_export.php Log: Replace addslashes routine. Fixes numerous problems with null values and escaping. Fixes bug #3572 http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/var_export.php?r1=1.11&r2=1.12&ty=u Index: pear/PHP_Compat/Compat/Function/var_export.php diff -u pear/PHP_Compat/Compat/Function/var_export.php:1.11 pear/PHP_Compat/Compat/Function/var_export.php:1.12 --- pear/PHP_Compat/Compat/Function/var_export.php:1.11 Tue Jan 25 23:55:13 2005 +++ pear/PHP_Compat/Compat/Function/var_export.php Mon Feb 28 03:46:06 2005 @@ -15,7 +15,7 @@ // | Authors: Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: var_export.php,v 1.11 2005/01/26 04:55:13 aidan Exp $ +// $Id: var_export.php,v 1.12 2005/02/28 08:46:06 aidan Exp $ /** @@ -25,7 +25,7 @@ * @package PHP_Compat * @link http://php.net/function.var_export * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * @since PHP 4.2.0 * @require PHP 4.0.0 (user_error) */ @@ -33,11 +33,13 @@ function var_export($array, $return = false) { // Common output variables - $indent = ' '; - $doublearrow = ' => '; - $lineend = ",\n"; - $stringdelim = '\''; - $newline = "\n"; + $indent = ' '; + $doublearrow = ' => '; + $lineend = ",\n"; + $stringdelim = '\''; + $newline = "\n"; + $find = array(null, '\\', '\''); + $replace = array('NULL', '\\\\', '\\\''); // Check the export isn't a simple string / int if (is_string($array)) { @@ -53,22 +55,26 @@ foreach ($array as $key => $value) { // If the key is a string, delimit it if (is_string($key)) { - $key = $stringdelim . addslashes($key) . $stringdelim; + $key = str_replace($find, $replace, $key); + $key = $stringdelim . $key . $stringdelim; } - // If the value is a string, delimit it - if (is_string($value)) { - $value = $stringdelim . addslashes($value) . $stringdelim; - } elseif (is_array($value)) { + // Delimit value + if (is_array($value)) { // We have an array, so do some recursion // Do some basic recursion while increasing the indent $recur_array = explode($newline, var_export($value, true)); - $recur_newarr = array (); + $temp_array = array(); foreach ($recur_array as $recur_line) { - $recur_newarr[] = $indent . $recur_line; + $temp_array[] = $indent . $recur_line; } - $recur_array = implode($newline, $recur_newarr); + $recur_array = implode($newline, $temp_array); $value = $newline . $recur_array; + } elseif (is_null($value)) { + $value = 'NULL'; + } else { + $value = str_replace($find, $replace, $value); + $value = $stringdelim . $value . $stringdelim; } // Piece together the line

« previous php.pear.cvs (#29920) next »