var_exportOutputs or returns a parsable string representation of a variable
&reftitle.description;
mixedvar_exportmixedexpressionboolreturnvar_export gets structured information about the
given variable. It is similar to var_dump
with one exception: the returned representation is valid PHP code.
&reftitle.parameters;
expression
The variable you want to export.
return
If used and set to &true;, var_export will return
the variable representation instead of outputing it.
¬e.uses-ob;
&reftitle.returnvalues;
Returns the variable representation when the return
parameter is used and evaluates to &true;. Otherwise, this function will
return &null;.
&reftitle.changelog;
&Version;&Description;5.1.0
Possibility to export classes and arrays containing classes using the
__set_state magic
method.
&reftitle.examples;
var_export Examples
]]>
&example.outputs;
1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
]]>
]]>
&example.outputs;
Exporting classes since PHP 5.1.0
var = 5;
var_export($a);
?>
]]>
&example.outputs;
5,
))
]]>
Using __set_state (since PHP 5.1.0)
var1 = $an_array['var1'];
$obj->var2 = $an_array['var2'];
return $obj;
}
}
$a = new A;
$a->var1 = 5;
$a->var2 = 'foo';
eval('$b = ' . var_export($a, true) . ';'); // $b = A::__set_state(array(
// 'var1' => 5,
// 'var2' => 'foo',
// ));
var_dump($b);
?>
]]>
&example.outputs;
int(5)
["var2"]=>
string(3) "foo"
}
]]>
&reftitle.notes;
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.
&reftitle.seealso;
print_rserializevar_dump