<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >debug_zval_dump</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Variáveis, Funções" HREF="ref.variables.html"><LINK REL="PREVIOUS" TITLE="Variáveis, Funções" HREF="ref.variables.html"><LINK REL="NEXT" TITLE="doubleval" HREF="function.doubleval.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.variables.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.doubleval.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.debug-zval-dump" ></A >debug_zval_dump</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN229438" ></A ><P > (PHP 4 >= 4.2.0, PHP 5)</P >debug_zval_dump -- Dumps a string representation of an internal zend value to output</DIV ><DIV CLASS="refsect1" ><A NAME="AEN229441" ></A ><H2 >Descrição</H2 >void <B CLASS="methodname" >debug_zval_dump</B > ( mixed variable )<BR ></BR ><P > Dumps a string representation of an internal zend value to output. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN229450" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >variable</CODE ></DT ><DD ><P > The variable being evaluated. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN229459" ></A ><H2 >Valores de retornado</H2 ><P > Não há valor retornado. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN229462" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN229465" ></A ><P ><B >Exemplo 1. <B CLASS="function" >debug_zval_dump()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$var1 </font><font color="#007700">= </font><font color="#DD0000">'Hello World'</font><font color="#007700">;<br /></font><font color="#0000BB">$var2 </font><font color="#007700">= </font><font color="#DD0000">''</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$var2 </font><font color="#007700">=& </font><font color="#0000BB">$var1</font><font color="#007700">;<br /><br /></font><font color="#0000BB">debug_zval_dump</font><font color="#007700">(&</font><font color="#0000BB">$var1</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >string(11) "Hello World" refcount(3)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Beware the <TT CLASS="literal" >refcount</TT >: </B > The <TT CLASS="literal" >refcount</TT > value returned by this function is non-obvious in certain circumstances. For example, a developer might expect the above example to indicate a <TT CLASS="literal" >refcount</TT > of <TT CLASS="literal" >2</TT >. The third reference is created when actually calling <B CLASS="function" >debug_zval_dump()</B >. </P ><P > This behavior is further compounded when a variable is not passed to <B CLASS="function" >debug_zval_dump()</B > by reference. To illustrate, consider a slightly modified version of the above example: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN229482" ></A ><P ><B >Exemplo 2. </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$var1 </font><font color="#007700">= </font><font color="#DD0000">'Hello World'</font><font color="#007700">;<br /></font><font color="#0000BB">$var2 </font><font color="#007700">= </font><font color="#DD0000">''</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$var2 </font><font color="#007700">=& </font><font color="#0000BB">$var1</font><font color="#007700">;<br /><br /></font><font color="#0000BB">debug_zval_dump</font><font color="#007700">(</font><font color="#0000BB">$var1</font><font color="#007700">); </font><font color="#FF8000">// not passed by reference, this time<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >string(11) "Hello World" refcount(1)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Why <TT CLASS="literal" >refcount(1)</TT >? Because a copy of <TT CLASS="literal" >$var1</TT > is being made, when the function is called. </P ><P > This function becomes even <SPAN CLASS="emphasis" ><I CLASS="emphasis" >more</I ></SPAN > confusing when a variable with a <TT CLASS="literal" >refcount</TT > of <TT CLASS="literal" >1</TT > is passed (by copy/value): </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN229495" ></A ><P ><B >Exemplo 3. </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$var1 </font><font color="#007700">= </font><font color="#DD0000">'Hello World'</font><font color="#007700">;<br /><br /></font><font color="#0000BB">debug_zval_dump</font><font color="#007700">(</font><font color="#0000BB">$var1</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >string(11) "Hello World" refcount(2)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > A <TT CLASS="literal" >refcount</TT > of <TT CLASS="literal" >2</TT >, here, is extremely non-obvious. Especially considering the above examples. So what's happening? </P ><P > When a variable has a single reference (as did <TT CLASS="literal" >$var1</TT > before it was used as an argument to <B CLASS="function" >debug_zval_dump()</B >), PHP's engine optimizes the manner in which it is passed to a function. Internally, PHP treats <TT CLASS="literal" >$var1</TT > like a reference (in that the <TT CLASS="literal" >refcount</TT > is increased for the scope of this function), with the caveat that <SPAN CLASS="emphasis" ><I CLASS="emphasis" >if</I ></SPAN > the passed reference happens to be written to, a copy is made, but only at the moment of writing. This is known as "copy on write." </P ><P > So, if <B CLASS="function" >debug_zval_dump()</B > happened to write to its sole parameter (and it doesn't), then a copy would be made. Until then, the parameter remains a reference, causing the <TT CLASS="literal" >refcount</TT > to be incremented to <TT CLASS="literal" >2</TT > for the scope of the function call. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN229513" ></A ><H2 >Veja também</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.var-dump.html" ><B CLASS="function" >var_dump()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.debug-backtrace.html" ><B CLASS="function" >debug_backtrace()</B ></A ></TD ></TR ><TR ><TD ><A HREF="language.references.html" >References Explained</A ></TD ></TR ><TR ><TD ><A HREF="http://www.zend.com/zend/art/ref-count.php" TARGET="_top" >Reference Counting and Aliasing (by Andi Gutmans)</A ></TD ></TR ><TR ><TD ><A HREF="http://derickrethans.nl/php_references_article.php" TARGET="_top" >References Explained (by Derick Rethans)</A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.variables.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.doubleval.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Variáveis, Funções</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.variables.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >doubleval</TD ></TR ></TABLE ></DIV ></BODY ></HTML >