reference/var/functions/unset.xml
d816a0fad6c458d9515f697cc89e26ca9d8069f5
d816a0fad6c458d9515f697cc89e26ca9d8069f5
...
...
@@ -3,7 +3,7 @@
3
3
<refentry xml:id="function.unset" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>unset</refname>
6
-
<refpurpose>Unset a given variable</refpurpose>
6
+
<refpurpose><function>unset</function> a given variable</refpurpose>
7
7
</refnamediv>
8
8
9
9
<refsect1 role="description">
...
...
@@ -11,7 +11,7 @@
11
11
<methodsynopsis>
12
12
<type>void</type><methodname>unset</methodname>
13
13
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
14
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
14
+
<methodparam rep="repeat"><type>mixed</type><parameter>vars</parameter></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
<function>unset</function> destroys the specified variables.
...
...
@@ -26,7 +26,8 @@
26
26
a function, only the local variable is destroyed. The variable
27
27
in the calling environment will retain the same value as before
28
28
<function>unset</function> was called.
29
-
<informalexample>
29
+
<example>
30
+
<title>Using <function>unset</function></title>
30
31
<programlisting role="php">
31
32
<![CDATA[
32
33
<?php
...
...
@@ -42,23 +43,14 @@ echo $foo;
42
43
?>
43
44
]]>
44
45
</programlisting>
45
-
</informalexample>
46
-
</para>
47
-
&example.outputs;
48
-
<para>
49
-
<informalexample>
50
-
<screen>
51
-
<![CDATA[
52
-
bar
53
-
]]>
54
-
</screen>
55
-
</informalexample>
46
+
</example>
56
47
</para>
57
48
<para>
58
49
To <function>unset</function> a global variable
59
50
inside of a function, then use
60
51
the <varname>$GLOBALS</varname> array to do so:
61
-
<informalexample>
52
+
<example>
53
+
<title><function>unset</function> a Global Variable</title>
62
54
<programlisting role="php">
63
55
<![CDATA[
64
56
<?php
...
...
@@ -72,7 +64,7 @@ foo();
72
64
?>
73
65
]]>
74
66
</programlisting>
75
-
</informalexample>
67
+
</example>
76
68
</para>
77
69
<para>
78
70
If a variable that is PASSED BY REFERENCE is
...
...
@@ -80,7 +72,8 @@ foo();
80
72
variable is destroyed. The variable in the calling environment
81
73
will retain the same value as before <function>unset</function>
82
74
was called.
83
-
<informalexample>
75
+
<example>
76
+
<title><function>unset</function> with Reference</title>
84
77
<programlisting role="php">
85
78
<![CDATA[
86
79
<?php
...
...
@@ -98,25 +91,15 @@ echo "$bar\n";
98
91
?>
99
92
]]>
100
93
</programlisting>
101
-
</informalexample>
102
-
</para>
103
-
&example.outputs;
104
-
<para>
105
-
<informalexample>
106
-
<screen>
107
-
<![CDATA[
108
-
something
109
-
something
110
-
]]>
111
-
</screen>
112
-
</informalexample>
94
+
</example>
113
95
</para>
114
96
<para>
115
97
If a static variable is <function>unset</function> inside of a
116
98
function, <function>unset</function> destroys the variable only in the
117
99
context of the rest of a function. Following calls will restore the
118
100
previous value of a variable.
119
-
<informalexample>
101
+
<example>
102
+
<title><function>unset</function> with Static Variable</title>
120
103
<programlisting role="php">
121
104
<![CDATA[
122
105
<?php
...
...
@@ -136,19 +119,7 @@ foo();
136
119
?>
137
120
]]>
138
121
</programlisting>
139
-
</informalexample>
140
-
</para>
141
-
&example.outputs;
142
-
<para>
143
-
<informalexample>
144
-
<screen>
145
-
<![CDATA[
146
-
Before unset: 1, after unset: 23
147
-
Before unset: 2, after unset: 23
148
-
Before unset: 3, after unset: 23
149
-
]]>
150
-
</screen>
151
-
</informalexample>
122
+
</example>
152
123
</para>
153
124
</refsect1>
154
125
...
...
@@ -165,10 +136,10 @@ Before unset: 3, after unset: 23
165
136
</listitem>
166
137
</varlistentry>
167
138
<varlistentry>
168
-
<term><parameter>...</parameter></term>
139
+
<term><parameter>vars</parameter></term>
169
140
<listitem>
170
141
<para>
171
-
Another variable ...
142
+
Further variables.
172
143
</para>
173
144
</listitem>
174
145
</varlistentry>
...
...
@@ -188,7 +159,7 @@ Before unset: 3, after unset: 23
188
159
<para>
189
160
<example>
190
161
<title><function>unset</function> example</title>
191
-
<programlisting role="php">
162
+
<programlisting role="php" annotations="non-interactive">
192
163
<![CDATA[
193
164
<?php
194
165
// destroy a single variable
...
...
@@ -203,32 +174,6 @@ unset($foo1, $foo2, $foo3);
203
174
]]>
204
175
</programlisting>
205
176
</example>
206
-
<example>
207
-
<title>Using <literal>(unset)</literal> casting</title>
208
-
<para>
209
-
<literal>(unset)</literal> casting is often confused with the
210
-
<function>unset</function> function. <literal>(unset)</literal>
211
-
casting serves only as a <literal>NULL</literal>-type cast, for
212
-
completeness. It does not alter the variable it's casting.
213
-
</para>
214
-
<programlisting role="php">
215
-
<![CDATA[
216
-
<?php
217
-
$name = 'Felipe';
218
-
219
-
var_dump((unset) $name);
220
-
var_dump($name);
221
-
?>
222
-
]]>
223
-
</programlisting>
224
-
&example.outputs;
225
-
<screen>
226
-
<![CDATA[
227
-
NULL
228
-
string(6) "Felipe"
229
-
]]>
230
-
</screen>
231
-
</example>
232
177
</para>
233
178
</refsect1>
234
179
...
...
@@ -237,13 +182,20 @@ string(6) "Felipe"
237
182
¬e.language-construct;
238
183
<note>
239
184
<para>
240
-
It is possible to unset even object properties visible in current context.
185
+
It is possible to unset object properties visible in the current context.
186
+
</para>
187
+
<para>
188
+
If declared,
189
+
<link linkend="object.get">__get()</link>
190
+
is called when accessing an unset property, and
191
+
<link linkend="object.set">__set()</link>
192
+
is called when setting an unset property.
241
193
</para>
242
194
</note>
243
195
<note>
244
196
<para>
245
197
It is not possible to unset <literal>$this</literal> inside an object
246
-
method since PHP 5.
198
+
method.
247
199
</para>
248
200
</note>
249
201
<note>
...
...
@@ -263,6 +215,7 @@ string(6) "Felipe"
263
215
<member><function>empty</function></member>
264
216
<member><link linkend="object.unset">__unset()</link></member>
265
217
<member><function>array_splice</function></member>
218
+
<member><link linkend="language.types.null.casting">(unset) casting</link></member>
266
219
</simplelist>
267
220
</para>
268
221
</refsect1>
269
222