language/variables.xml
00e8d1f2b04d3c55e7e31a323be68f90d1662c7d
...
...
@@ -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.
...
...
@@ -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
...
...
@@ -463,7 +469,7 @@ function test()
463
469
</para>
464
470

465
471
<para>
466
-
Static variables can be assigned values which are the,
472
+
Static variables can be assigned values which are the
467
473
result of constant expressions, but dynamic expressions, such as function
468
474
calls, will cause a parse error.
469
475
</para>
...
...
@@ -487,6 +493,34 @@ function foo(){
487
493
</example>
488
494
</para>
489
495

496
+
<para>
497
+
As of PHP 8.1.0, when a method using static variables is inherited (but not overridden),
498
+
the inherited method will now share static variables with the parent method.
499
+
This means that static variables in methods now behave the same way as static properties.
500
+
</para>
501
+

502
+
<example>
503
+
<title>Usage of static Variables in Inherited Methods</title>
504
+
<programlisting role="php">
505
+
<![CDATA[
506
+
<?php
507
+
class Foo {
508
+
public static function counter() {
509
+
static $counter = 0;
510
+
$counter++;
511
+
return $counter;
512
+
}
513
+
}
514
+
class Bar extends Foo {}
515
+
var_dump(Foo::counter()); // int(1)
516
+
var_dump(Foo::counter()); // int(2)
517
+
var_dump(Bar::counter()); // int(3), prior to PHP 8.1.0 int(1)
518
+
var_dump(Bar::counter()); // int(4), prior to PHP 8.1.0 int(2)
519
+
?>
520
+
]]>
521
+
</programlisting>
522
+
</example>
523
+

490
524
<note>
491
525
<para>
492
526
Static declarations are resolved in compile-time.
...
...
@@ -513,13 +547,13 @@ function foo(){
513
547
<?php
514
548
function test_global_ref() {
515
549
global $obj;
516
-
$new = new stdclass;
550
+
$new = new stdClass;
517
551
$obj = &$new;
518
552
}
519
553

520
554
function test_global_noref() {
521
555
global $obj;
522
-
$new = new stdclass;
556
+
$new = new stdClass;
523
557
$obj = $new;
524
558
}
525
559

...
...
@@ -557,7 +591,7 @@ function &get_instance_ref() {
557
591
echo 'Static object: ';
558
592
var_dump($obj);
559
593
if (!isset($obj)) {
560
-
$new = new stdclass;
594
+
$new = new stdClass;
561
595
// Assign a reference to the static variable
562
596
$obj = &$new;
563
597
}
...
...
@@ -575,7 +609,7 @@ function &get_instance_noref() {
575
609
echo 'Static object: ';
576
610
var_dump($obj);
577
611
if (!isset($obj)) {
578
-
$new = new stdclass;
612
+
$new = new stdClass;
579
613
// Assign the object to the static variable
580
614
$obj = $new;
581
615
}
...
...
@@ -665,7 +699,7 @@ $$a = 'world';
665
699
<programlisting role="php">
666
700
<![CDATA[
667
701
<?php
668
-
echo "$a ${$a}";
702
+
echo "$a {$$a}";
669
703
?>
670
704
]]>
671
705
</programlisting>
672
706