|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81675 Undocumented change in get_class_vars behaviour with static properties in 8.1
Submitted: 2021-11-30 10:56 UTC Modified: 2021-11-30 14:24 UTC
Avg. Score:4.2 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:3 (60.0%)
From: diede at yoast dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 8.1.0 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-11-30 10:56 UTC] diede at yoast dot com
I have a feeling that `get_class_vars()` received a bugfix. Previously it included the current value of a static property, but now returns the default/initial value instead. This now matches the documentation, but the behaviour of previous PHP versions didn't match the documentation.

I can't find anything in the changelogs, docs and RFCs. Here's where we looked:

This could at the very least be considered a breaking change and should be documented.

Test script:
class MyClass {
    public static $myProperty;

MyClass::$myProperty = 3;
var_dump( get_class_vars( MyClass::class ) );

Expected result:
// Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13
array(1) {

Actual result:
// Output for 8.1.0
array(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-30 12:21 UTC]
-Type: Bug +Type: Documentation Problem -Package: *General Issues +Package: Scripting Engine problem
 [2021-11-30 12:21 UTC] runs without OPcache.  With OPcache enabled, you already
got the same result as with PHP 8.1.  This inconsistency[1] has
now been fixed[2]; I'm not sure whether this should be documented,
given that OPcache is likely always enabled in production
environments at least.

[1] <>
[2] <>
 [2021-11-30 13:40 UTC] bugs dot php dot net_nospam at adviesenzo dot nl
> I'm not sure whether this should be documented,
given that OPcache is likely always enabled in production
environments at least.

Well, considering it took us a not insignificant amount of time to pin down what was causing the difference in behaviour and that the change removes a difference between typical production vs develop environments which people may have run into and got stuck on trying to figure out before, I think documenting this would be useful, if for no other reason than to save other people running into the same/similar situation debug time.
 [2021-11-30 14:11 UTC]
As the behavior was there for quite a long time, adding a note for buggy behavior with PHP < 8.1 without opcache seems reasonable.
 [2021-11-30 14:24 UTC]
-Status: Open +Status: Verified
 [2022-09-22 10:07 UTC] pedder55655 at gmx dot net
I can can confirm this. 

I use a static object for localisation and modify the static variables upon load-up with those from the user's preference. After upgrade to php 8.1, they all see the default language as my property assignments have no effect anymore.
 [2023-01-12 05:09 UTC] samira dot akhlaqi314 at gmail dot com
A really good post, very thankful and hopeful that you will write many more posts like this one.		

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 14:01:30 2024 UTC