philip Tue Jan 1 15:38:08 2002 EDT
Modified files:
/phpdoc/en/functions var.xml
Log:
print_r: Expanded example, reworded a bit, See also, and implemented the
former Warning as a Note. (<4.0.4 print_r($GLOBALS) is bad)
Index: phpdoc/en/functions/var.xml
diff -u phpdoc/en/functions/var.xml:1.88 phpdoc/en/functions/var.xml:1.89
--- phpdoc/en/functions/var.xml:1.88 Mon Dec 31 14:01:52 2001
+++ phpdoc/en/functions/var.xml Tue Jan 1 15:38:06 2002
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.88 $ -->
+<!-- $Revision: 1.89 $ -->
<reference id="ref.variables">
<title>Variable Functions</title>
<titleabbrev>Variables</titleabbrev>
@@ -898,9 +898,9 @@
</funcprototype>
</funcsynopsis>
<simpara>
- This function displays information about the values of variables
- in a way that's readable by humans. If given a <type>string</type>,
- <type>integer</type> or <type>float</type>, the value itself will be
+ <function>print_r</function> displays information about a variable
+ in a way that's readable by humans. If given a <type>string</type>,
+ <type>integer</type> or <type>float</type>, the value itself will be
printed. If given an <type>array</type>,
values will be presented in a format that shows keys and
elements. Similar notation is used for <type>object</type>s.
@@ -910,23 +910,56 @@
pointer to the end. Use <function>reset</function> to bring
it back to beginning.
</simpara>
- &tip.ob-capture;
- <simpara>
- Compare <function>print_r</function> to
- <function>var_dump</function>.
- </simpara>
+ &tip.ob-capture;
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
+<pre>
<?php
-$a = array (1, 2, array ("a", "b", "c"));
-print_r ($a);
+ $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
+ print_r ($a);
?>
+</pre>
]]>
</programlisting>
</informalexample>
</para>
+ <para>
+ Which will output:
+ <screen>
+<![CDATA[
+<pre>
+Array
+(
+ [a] => apple
+ [b] => banana
+ [c] => Array
+ (
+ [0] => x
+ [1] => y
+ [2] => z
+ )
+)
+</pre>
+]]>
+ </screen>
+ </para>
+ <note>
+ <simpara>
+ Prior to PHP 4.0.4, <function>print_r</function> will continue forever
+ if given an <type>array</type> or <type>object</type> that
+ contains a direct or indirect reference to itself. An example
+ is <literal>print_r($GLOBALS)</literal> because
+ <literal>$GLOBALS</literal> is itself a global variable that
+ contains a reference to itself.
+ </simpara>
+ </note>
+ <simpara>
+ See also <function>ob_start</function>, <function>var_dump</function>,
+ and <function>var_export</function>.
+ </simpara>
+
</refsect1>
</refentry>