PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
var_export - Outputs or returns a parsable string representation of a variable
Code Examples

var_export( mixed$value, [bool$return = false] ): string|null

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.



The variable you want to export.


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.



Variables of type resource couldn't be exported by this function.


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.


When var_export exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.


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.


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.

Related Functions

Example of var_export

Show all examples for var_export

PHP Version:

Function var_export:

Variable handling Functions

Most used PHP functions