diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-17 10:47:30 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-18 11:18:19 +0100 |
commit | 5d160e309ed207e618d49029e51c9c2dc2c5e61c (patch) | |
tree | a6f1deb6f582e42792a8dccedb117a26decd3e65 /UPGRADING | |
parent | e03284739f4a3a1052dfe5497fbf06c1b206f895 (diff) | |
download | php-git-5d160e309ed207e618d49029e51c9c2dc2c5e61c.tar.gz |
Fix static variable behavior with inheritance
When a method is inherited, the static variables will now always
use the initial values, rather than the values at the time of
inheritance. As such, behavior no longer depends on whether
inheritance happens before or after a method has been called.
This is implemented by always keeping static_variables as the
original values, and static_variables_ptr as the modified copy.
Closes GH-6705.
Diffstat (limited to 'UPGRADING')
-rw-r--r-- | UPGRADING | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -37,6 +37,28 @@ PHP 8.1 UPGRADE NOTES // is deprecated RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg + . When a method using static variables is inherited, the inherited method + will now initialize the static variables to their original values, rather + than the values at the time of inheritance: + + class A { + public function counter() { + static $counter = 0; + $counter++; + return $counter; + } + } + + var_dump((new A)->counter()); // int(1) + + eval('class B extends A {}'); // eval() to prevent early binding. + + var_dump((new B)->counter()); // int(1), previously int(2) + var_dump((new A)->counter()); // int(2) + var_dump((new B)->counter()); // int(2), previously int(3) + + Previously the behavior would be different depending on whether A::counter() + was called before class B was declared, or after it was declared. - Fileinfo: . The fileinfo functions now accept and return, respectively, finfo objects |