<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var-representation.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.var-representation.php',
    1 => 'var_representation',
    2 => 'Returns a short, readable, parsable string representation of a variable',
  ),
  'up' => 
  array (
    0 => 'ref.var-representation.php',
    1 => 'var_representation Funktionen',
  ),
  'prev' => 
  array (
    0 => 'ref.var-representation.php',
    1 => 'var_representation Funktionen',
  ),
  'next' => 
  array (
    0 => 'refs.remote.other.php',
    1 => 'Sonstige Dienste',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/var_representation/functions/var-representation.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.var-representation" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">var_representation</h1>
  <p class="verinfo">(PECL var_representation &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">var_representation</span> &mdash; <span class="dc-title">Returns a short, readable, parsable string representation of a variable</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.var-representation-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>var_representation</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   <span class="function"><strong>var_representation()</strong></span> (from the var_representation PECL) returns a string with structured information about the 
   given variable. It is similar to <span class="function"><a href="function.var-export.php" class="function">var_export()</a></span> with differences in indentation, string escaping, and array representations.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.var-representation-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">value</code></dt>
    <dd>
     <p class="para">
       The variable to generate a representation of.
     </p>
    </dd>
   
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <p class="para">
       Bitmask consisting of
       <strong><code><a href="var-representation.constants.php#constant.var-representation-single-line">VAR_REPRESENTATION_SINGLE_LINE</a></code></strong>, 
       <strong><code><a href="var-representation.constants.php#constant.var-representation-unescaped">VAR_REPRESENTATION_UNESCAPED</a></code></strong>.
       The behaviour of these constants is described on the
       <a href="var-representation.constants.php" class="link">var_representation constants</a> page.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.var-representation-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Returns the variable representation.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.var-representation-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>var_representation()</strong></span> Examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$a </span><span style="color: #007700">= [</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">, [</span><span style="color: #DD0000">'key' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'value'</span><span style="color: #007700">]];<br />echo </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">VAR_REPRESENTATION_SINGLE_LINE</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">[
  1,
  2,
  [
    &#039;key&#039; =&gt; &#039;value&#039;,
  ],
]
[1, 2, [&#039;key&#039; =&gt; &#039;value&#039;]]</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Beispiel #2 Escaping control characters</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Length: 123\r\n"</span><span style="color: #007700">);</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">&quot;Content-Length: 123\r\n&quot;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Beispiel #3 Exporting <span class="classname"><a href="class.stdclass.php" class="classname">stdClass</a></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$person </span><span style="color: #007700">= new </span><span style="color: #0000BB">stdClass</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$person</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #DD0000">'ElePHPant ElePHPantsdotter'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$person</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">website </span><span style="color: #007700">= </span><span style="color: #DD0000">'https://php.net/elephpant.php'</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #0000BB">$person</span><span style="color: #007700">);</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">(object) [
  &#039;name&#039; =&gt; &#039;ElePHPant ElePHPantsdotter&#039;,
  &#039;website&#039; =&gt; &#039;https://php.net/elephpant.php&#039;,
]</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>Beispiel #4 Exporting classes</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A </span><span style="color: #007700">{ public </span><span style="color: #0000BB">$var</span><span style="color: #007700">; }<br /></span><span style="color: #0000BB">$a </span><span style="color: #007700">= new </span><span style="color: #0000BB">A</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">var </span><span style="color: #007700">= </span><span style="color: #0000BB">5</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">\A::__set_state([
  &#039;var&#039; =&gt; 5,
])</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5">
    <p><strong>Beispiel #5 Using <a href="language.oop5.magic.php#object.set-state" class="link">__set_state()</a></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br />    public </span><span style="color: #0000BB">$var1</span><span style="color: #007700">;<br />    public </span><span style="color: #0000BB">$var2</span><span style="color: #007700">;<br /><br />    public static function </span><span style="color: #0000BB">__set_state</span><span style="color: #007700">(</span><span style="color: #0000BB">$an_array</span><span style="color: #007700">)<br />    {<br />        </span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">A</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">var1 </span><span style="color: #007700">= </span><span style="color: #0000BB">$an_array</span><span style="color: #007700">[</span><span style="color: #DD0000">'var1'</span><span style="color: #007700">];<br />        </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">var2 </span><span style="color: #007700">= </span><span style="color: #0000BB">$an_array</span><span style="color: #007700">[</span><span style="color: #DD0000">'var2'</span><span style="color: #007700">];<br />        return </span><span style="color: #0000BB">$obj</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$a </span><span style="color: #007700">= new </span><span style="color: #0000BB">A</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">var1 </span><span style="color: #007700">= </span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">var2 </span><span style="color: #007700">= </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">;<br /><br />eval(</span><span style="color: #DD0000">'$b = ' </span><span style="color: #007700">. </span><span style="color: #0000BB">var_representation</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">) . </span><span style="color: #DD0000">';'</span><span style="color: #007700">); </span><span style="color: #FF8000">// $b = \A::__set_state([<br />                                              //   'var1' =&gt; 5,<br />                                              //   'var2' =&gt; 'foo',<br />                                              // ]);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(A)#2 (2) {
  [&quot;var1&quot;]=&gt;
  int(5)
  [&quot;var2&quot;]=&gt;
  string(3) &quot;foo&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.var-representation-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.var-export.php" class="function" rel="rdfs-seeAlso">var_export()</a> - Liefert den Inhalt einer Variablen als parsbaren PHP-Code</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>