Function.var-export

Aus PHP-Wiki

Wechseln zu: Navigation, Suche
Prepaid Handy und RechtsschutzversicherungPrivate Krankenversicherung . Vergleichsportal für persönliche Finanzen

var_export — Outputs or returns a parsable string representation of a variable

Inhaltsverzeichnis

Beschreibung

mixed var_export ( mixed $expression [, bool $return ] ) 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.

Parameter-Liste

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. Hinweis: Diese Funktion benutzt intern Ausgabenpufferung mit diesem Parameter und kann daher nicht in einer ob_start() Callbackfunktion eingesetzt werden.

Rückgabewerte

Returns the variable representation when the return parameter is used and evaluates to TRUE. Otherwise, this function will return NULL.

ChangeLog

Version Beschreibung 5.1.0 Possibility to export classes and arrays containing classes using the __set_state magic method.

Beispiele

=== #1 var_export() Examples

<?php
$a = array (1, 2, array ("a", "b", "c"));
var_export($a);
?>
Das oben gezeigte Beispiel erzeugt folgende
Ausgabe:
array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)
<?php
 
$b = 3.1;
$v = var_export($b, true);
echo $v;
 
?>
Das oben gezeigte Beispiel erzeugt folgende
Ausgabe:
3.1

Beispiel #2 Exporting classes since PHP 5.1.0

<?php
class A { public $var; }
$a = new A;
$a===
 
 
 
 
 
 
=== #3 Using [[language.oop5.magic.php#language.oop5.magic.set===
 
 
 
 
 
 
 
 
<div class=|
 
==Anmerkungen==
 
 
  Hinweis: 
 
    Variables of type resource]] couldn&#039;t be exported by this
    function.
   <br />
 
  Hinweis: 
 
    '''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 [[function.serialize|serialize()]].
   <br />
 
 
 
 
 
 
==Siehe auch==
* [[function.print-r|print_r()]]
* [[function.serialize|serialize()]]
* [[function.var-dump|var_dump()]]
 
[[Kategorie:PHP 4|V]]
[[Kategorie:PHP 5|V]]
[[Kategorie:Funktionen zur Behandlung von Variablen|V]]
Persönliche Werkzeuge