Skip to content

Commit ac54035

Browse files
committed
Add UPGRADING note
1 parent a0ab4ad commit ac54035

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

UPGRADING

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ PHP 8.1 UPGRADE NOTES
3737
// is deprecated
3838

3939
RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
40+
. When a method using static variables is inherited, the inherited method
41+
will now initialize the static variables to their original values, rather
42+
than the values at the time of inheritance:
43+
44+
class A {
45+
public function counter() {
46+
static $counter = 0;
47+
$counter++;
48+
return $counter;
49+
}
50+
}
51+
52+
var_dump((new A)->counter()); // int(1)
53+
54+
eval('class B extends A {}'); // eval() to prevent early binding.
55+
56+
var_dump((new B)->counter()); // int(1), previously int(2)
57+
var_dump((new A)->counter()); // int(2)
58+
var_dump((new B)->counter()); // int(2), previously int(3)
59+
60+
Previously the behavior would be different depending on whether A::counter()
61+
was called before class B was declared, or after it was declared.
4062

4163
- Fileinfo:
4264
. The fileinfo functions now accept and return, respectively, finfo objects

0 commit comments

Comments
 (0)