Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2640

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Dumps a string representation of an internal zend value to output</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.boolval.html">boolval</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.doubleval.html">doubleval</a></div>
 <div class="up"><a href="ref.var.html">Variable handling Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.debug-zval-dump" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">debug_zval_dump</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">debug_zval_dump</span> &mdash; <span class="dc-title">Dumps a string representation of an internal zend value to output</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.debug-zval-dump-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>debug_zval_dump</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$variable</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Dumps a string representation of an internal zend value to output.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.debug-zval-dump-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">variable</code></em></span>
     <dd>

      <p class="para">
       The variable being evaluated.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.debug-zval-dump-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No value is returned.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.debug-zval-dump-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-5244">
    <p><strong>Example #1  <span class="function"><strong>debug_zval_dump()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&amp;&nbsp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&amp;string(11) &quot;Hello World&quot; refcount(3)
</pre></div>
    </div>
   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Beware the <em>refcount</em></strong><br />
   <p class="para">
    The <em>refcount</em> value returned by this function is
    non-obvious in certain circumstances. For example, a developer might
    expect the above example to indicate a <em>refcount</em> of
    <em>2</em>. The third reference is created when actually
    calling  <span class="function"><strong>debug_zval_dump()</strong></span>.
   </p>
   <p class="para">
    This behavior is further compounded when a variable is not passed to
     <span class="function"><strong>debug_zval_dump()</strong></span> by reference. To illustrate, consider
    a slightly modified version of the above example:
   </p>
   <p class="para">
    <div class="example" id="example-5245">
     
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&amp;&nbsp;</span><span style="color: #0000BB">$var1</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;not&nbsp;passed&nbsp;by&nbsp;reference,&nbsp;this&nbsp;time<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>The above example will output:</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
string(11) &quot;Hello World&quot; refcount(1)
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    Why <em>refcount(1)</em>? Because a copy of <em>$var1</em> is
    being made, when the function is called.
   </p>
   <p class="para">
    This function becomes even <em class="emphasis">more</em> confusing when a
    variable with a <em>refcount</em> of <em>1</em> is
    passed (by copy/value):
   </p>
   <p class="para">
    <div class="example" id="example-5246">
     
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">debug_zval_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>The above example will output:</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
string(11) &quot;Hello World&quot; refcount(2)
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    A <em>refcount</em> of <em>2</em>, here, is extremely
    non-obvious. Especially considering the above examples. So what&#039;s
    happening?
   </p>
   <p class="para">
    When a variable has a single reference (as did <em>$var1</em>
    before it was used as an argument to  <span class="function"><strong>debug_zval_dump()</strong></span>),
    PHP&#039;s engine optimizes the manner in which it is passed to a function.
    Internally, PHP treats <em>$var1</em> like a reference (in that
    the <em>refcount</em> is increased for the scope of this
    function), with the caveat that <em class="emphasis">if</em> the passed reference
    happens to be written to, a copy is made, but only at the moment of
    writing. This is known as &quot;copy on write.&quot;
   </p>
   <p class="para">
    So, if  <span class="function"><strong>debug_zval_dump()</strong></span> happened to write to its sole
    parameter (and it doesn&#039;t), then a copy would be made. Until then, the
    parameter remains a reference, causing the <em>refcount</em> to
    be incremented to <em>2</em> for the scope of the function call.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.debug-zval-dump-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.var-dump.html" class="function" rel="rdfs-seeAlso">var_dump()</a> - Dumps information about a variable</span></li>
    <li class="member"> <span class="function"><a href="function.debug-backtrace.html" class="function" rel="rdfs-seeAlso">debug_backtrace()</a> - Generates a backtrace</span></li>
    <li class="member"><a href="language.references.html" class="link">References Explained</a></li>
    <li class="member"><a href="http://derickrethans.nl/php_references_article.php" class="link external">&raquo;&nbsp;References Explained (by Derick Rethans)</a></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.boolval.html">boolval</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.doubleval.html">doubleval</a></div>
 <div class="up"><a href="ref.var.html">Variable handling Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>