var_export in PHP 5
So var_export(mixed $expression [, bool $return = false ] ) outputs or returns a parsable string representation of a variable, it gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code.
It’s quite simple to use, below is an example of how to use it.
1 2 3 4 5 6 | class A { public $var; } $a = new A; $a->var = 5; var_export($a); |
The output from the above code would be…
A::__set_state(array( 'var' => 5, ))
Note: var_export() does not handle circular references as it would be close to impossible to generate parsable PHP code for that. If you want to do something with the full representation of an array or object, use serialize().



Caution! var_export will add a backslash to single quotes (‘).
You may want to use stripslashes() to remove the mysteriously added backslashes.