Zend_Debug.xml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.debug.dumping">
  4. <title>Dumping Variables</title>
  5. <para>
  6. The static method <methodname>Zend_Debug::dump()</methodname> prints or returns
  7. information about an expression. This simple technique of debugging is
  8. common because it is easy to use in an ad hoc fashion and requires no
  9. initialization, special tools, or debugging environment.
  10. </para>
  11. <example id="zend.debug.dumping.example">
  12. <title>Example of dump() method</title>
  13. <programlisting language="php"><![CDATA[
  14. Zend_Debug::dump($var, $label = null, $echo = true);
  15. ]]></programlisting>
  16. </example>
  17. <para>
  18. The <varname>$var</varname> argument specifies the expression or variable
  19. about which the <methodname>Zend_Debug::dump()</methodname> method outputs
  20. information.
  21. </para>
  22. <para>
  23. The <varname>$label</varname> argument is a string to be prepended to the
  24. output of <methodname>Zend_Debug::dump()</methodname>. It may be useful, for
  25. example, to use labels if you are dumping information about multiple
  26. variables on a given screen.
  27. </para>
  28. <para>
  29. The boolean <varname>$echo</varname> argument specifies whether the output
  30. of <methodname>Zend_Debug::dump()</methodname> is echoed or not.
  31. If <constant>TRUE</constant>, the output is echoed.
  32. Regardless of the value of the <varname>$echo</varname> argument, the
  33. return value of this method contains the output.
  34. </para>
  35. <para>
  36. It may be helpful to understand that
  37. <methodname>Zend_Debug::dump()</methodname> method wraps the <acronym>PHP</acronym> function
  38. <ulink url="http://php.net/var_dump"><methodname>var_dump()</methodname></ulink>.
  39. If the output stream is detected as a web presentation,
  40. the output of <methodname>var_dump()</methodname> is escaped using <ulink
  41. url="http://php.net/htmlspecialchars"><methodname>htmlspecialchars()</methodname></ulink>
  42. and wrapped with (X)HTML <command>&lt;pre&gt;</command> tags.
  43. </para>
  44. <tip>
  45. <title>Debugging with Zend_Log</title>
  46. <para>
  47. Using <methodname>Zend_Debug::dump()</methodname> is best for ad hoc
  48. debugging during software development. You can add code to dump
  49. a variable and then remove the code very quickly.
  50. </para>
  51. <para>
  52. Also consider the <link linkend="zend.log.overview">Zend_Log</link>
  53. component when writing more permanent debugging code. For example,
  54. you can use the <constant>DEBUG</constant> log level and the
  55. <link linkend="zend.log.writers.stream">stream log writer</link> to
  56. output the string returned by <methodname>Zend_Debug::dump()</methodname>.
  57. </para>
  58. </tip>
  59. </sect1>
  60. <!--
  61. vim:se ts=4 sw=4 et:
  62. -->