var_export
var_export gets structured information about the given variable. It is similar to var_dump with one exception: the returned representation is valid PHP code.
Parameters
- value
-
The variable you want to export.
- return
-
If used and set to true, var_export will return the variable representation instead of outputting it.
Return Values
Returns the variable representation when the return parameter is used and evaluates to true. Otherwise, this function will return null.
Notes
Note:
Variables of type resource couldn't be exported by this function.
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.
Warning:
When var_export exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.
Note:
To be able to evaluate the PHP generated by var_export, all processed objects must implement the magic __set_state method. The only exception is stdClass, which is exported using an array cast to an object.
Changelog
Version | Description |
7.3.0 |
Now exports stdClass objects as an array cast to
an object ((object) array( ... ) ), rather than using the
nonexistent method stdClass::__setState.
The practical effect is that now stdClass is
exportable, and the resulting code will even work on earlier versions of
PHP.
|