vrana Thu Nov 3 05:59:41 2005 EDT
Modified files:
/phpdoc/en/reference/var/functions unset.xml
Log:
Unsetting static variable (bug #34865)
Move $GLOBALS example below global
http://cvs.php.net/diff.php/phpdoc/en/reference/var/functions/unset.xml?r1=1.12&r2=1.13&ty=u
Index: phpdoc/en/reference/var/functions/unset.xml
diff -u phpdoc/en/reference/var/functions/unset.xml:1.12
phpdoc/en/reference/var/functions/unset.xml:1.13
--- phpdoc/en/reference/var/functions/unset.xml:1.12 Fri Mar 11 11:18:19 2005
+++ phpdoc/en/reference/var/functions/unset.xml Thu Nov 3 05:59:39 2005
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.12 $ -->
+<!-- $Revision: 1.13 $ -->
<!-- splitted from ./en/functions/var.xml, last change in rev 1.2 -->
<refentry id="function.unset">
<refnamediv>
@@ -82,6 +82,26 @@
</informalexample>
</para>
<para>
+ If you would like to <function>unset</function> a global variable
+ inside of a function, you can use
+ the <varname>$GLOBALS</varname> array to do so:
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function foo()
+{
+ unset($GLOBALS['bar']);
+}
+
+$bar = "something";
+foo();
+?>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
+ <para>
If a variable that is PASSED BY REFERENCE is
<function>unset</function> inside of a function, only the local
variable is destroyed. The variable in the calling environment
@@ -120,18 +140,21 @@
</para>
<para>
If a static variable is <function>unset</function> inside of a
- function, <function>unset</function> destroys the variable and all
- its references.
+ function, <function>unset</function> destroys the variable only in the
+ context of the rest of a function. Following calls will restore the
+ previous value of a variable.
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
-function foo()
+function foo()
{
- static $a;
- $a++;
- echo "$a\n";
- unset($a);
+ static $bar;
+ $bar++;
+ echo "Before unset: $bar, ";
+ unset($bar);
+ $bar = 23;
+ echo "after unset: $bar\n";
}
foo();
@@ -147,33 +170,13 @@
<informalexample>
<screen>
<![CDATA[
-1
-2
-3
+Before unset: 1, after unset: 23
+Before unset: 2, after unset: 23
+Before unset: 3, after unset: 23
]]>
</screen>
</informalexample>
</para>
- <para>
- If you would like to <function>unset</function> a global variable
- inside of a function, you can use
- the <varname>$GLOBALS</varname> array to do so:
- <informalexample>
- <programlisting role="php">
-<![CDATA[
-<?php
-function foo()
-{
- unset($GLOBALS['bar']);
-}
-
-$bar = "something";
-foo();
-?>
-]]>
- </programlisting>
- </informalexample>
- </para>
¬e.language-construct;