Created
October 2, 2013 14:38
-
-
Save jtsternberg/6794786 to your computer and use it in GitHub Desktop.
A `print_r` or `var_dump` replacement that expands the variable into valid PHP code. (for copy/pasting back into the project, etc)
This file contains 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 | |
/** | |
* A `print_r` or `var_dump` replacement that expands the variable into valid PHP code. | |
* @uses var_export | |
* @param array|object $array_or_object $variable to expand/view | |
* @param boolean $echo Whether to return or display the data | |
* @return string Variable representation that is valid PHP code. | |
*/ | |
function expand_code( $array_or_object, $echo = true ) { | |
$expanded = '<xmp>$expanded = '. str_ireplace( 'stdClass::__set_state', '(object) ', var_export( $array_or_object, true ) ) .'</xmp>'; | |
if ( $echo ) | |
echo $expanded; | |
else | |
return $expanded; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment