language/variables.xml
5700871f9d037a59d137be318f89deb7e146bbf6
...
...
@@ -138,7 +138,7 @@ $bar = &test(); // Invalid.
138
138
var_dump($unset_var);
139
139

140
140
// Boolean usage; outputs 'false' (See ternary operators for more on this syntax)
141
-
echo($unset_bool ? "true\n" : "false\n");
141
+
echo $unset_bool ? "true\n" : "false\n";
142
142

143
143
// String usage; outputs 'string(3) "abc"'
144
144
$unset_str .= 'abc';
...
...
@@ -148,7 +148,7 @@ var_dump($unset_str);
148
148
$unset_int += 25; // 0 + 25 => 25
149
149
var_dump($unset_int);
150
150

151
-
// Float/double usage; outputs 'float(1.25)'
151
+
// Float usage; outputs 'float(1.25)'
152
152
$unset_float += 1.25;
153
153
var_dump($unset_float);
154
154

...
...
@@ -169,7 +169,8 @@ var_dump($unset_obj);
169
169
Relying on the default value of an uninitialized variable is problematic
170
170
in the case of including one file into another which uses the same
171
171
variable name.
172
-
<link linkend="errorfunc.constants.errorlevels.e-notice">E_NOTICE</link> level error is issued in case of
172
+
<constant>E_WARNING</constant> (prior to PHP 8.0.0, <constant>E_NOTICE</constant>)
173
+
level error is issued in case of
173
174
working with uninitialized variables, however not in the case of appending
174
175
elements to the uninitialized array. <function>isset</function> language
175
176
construct can be used to detect if a variable has been already initialized.
...
...
@@ -225,8 +226,8 @@ var_dump($unset_obj);
225
226
<simpara>
226
227
The scope of a variable is the context within which it is defined.
227
228
For the most part all PHP variables only have a single scope.
228
-
This single scope spans included and required files as well. For
229
-
example:
229
+
This single scope spans <function>include</function>d and
230
+
<function>require</function>d files as well. For example:
230
231
</simpara>
231
232
<informalexample>
232
233
<programlisting role="php">
...
...
@@ -264,7 +265,12 @@ test();
264
265
</informalexample>
265
266

266
267
<simpara>
267
-
This script will not produce any output because the echo statement
268
+
This script will generate an undefined variable <constant>E_WARNING</constant>
269
+
(or a <constant>E_NOTICE</constant> prior to PHP 8.0.0)
270
+
diagnostic. However, if the
271
+
<link linkend="ini.display-errors">display_errors</link> INI setting is set to hide
272
+
such diagnostics then nothing at all will be outputted.
273
+
This is because the echo statement
268
274
refers to a local version of the <varname>$a</varname> variable,
269
275
and it has not been assigned a value within this scope. You may
270
276
notice that this is a little bit different from the C language in
...
...
@@ -541,13 +547,13 @@ var_dump(Bar::counter()); // int(4), prior to PHP 8.1.0 int(2)
541
547
<?php
542
548
function test_global_ref() {
543
549
global $obj;
544
-
$new = new stdclass;
550
+
$new = new stdClass;
545
551
$obj = &$new;
546
552
}
547
553

548
554
function test_global_noref() {
549
555
global $obj;
550
-
$new = new stdclass;
556
+
$new = new stdClass;
551
557
$obj = $new;
552
558
}
553
559

...
...
@@ -585,7 +591,7 @@ function &get_instance_ref() {
585
591
echo 'Static object: ';
586
592
var_dump($obj);
587
593
if (!isset($obj)) {
588
-
$new = new stdclass;
594
+
$new = new stdClass;
589
595
// Assign a reference to the static variable
590
596
$obj = &$new;
591
597
}
...
...
@@ -603,7 +609,7 @@ function &get_instance_noref() {
603
609
echo 'Static object: ';
604
610
var_dump($obj);
605
611
if (!isset($obj)) {
606
-
$new = new stdclass;
612
+
$new = new stdClass;
607
613
// Assign the object to the static variable
608
614
$obj = $new;
609
615
}
...
...
@@ -693,7 +699,7 @@ $$a = 'world';
693
699
<programlisting role="php">
694
700
<![CDATA[
695
701
<?php
696
-
echo "$a ${$a}";
702
+
echo "$a {$$a}";
697
703
?>
698
704
]]>
699
705
</programlisting>
700
706