|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80821 ReflectionProperty::getDefaultValue() returns current value for statics
Submitted: 2021-03-02 23:17 UTC Modified: -
From: dktapps at pmmp dot io Assigned:
Status: Open Package: Reflection related
PHP Version: 8.0.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: dktapps at pmmp dot io
New email:
PHP Version: OS:


 [2021-03-02 23:17 UTC] dktapps at pmmp dot io
When OPcache is not present, default_static_members_table gets written to directly  instead of being copied.
I'm not sure why this is; at best it seems like a premature optimisation, especially considering that OPcache should be used in the 99% case.

This problem has plagued ext-pthreads and other threading extensions for many years (since even before PHP 7.0), creating inconsistencies of behaviour when OPcache is used, vs when it is not.

This can finally be seen in userland in PHP 8.0 with the script below, which demonstrates the problem using reflection.

Side note: A similar problem/inconsistency also exists with function static_variables, but these can't be inspected using reflection, since PHP doesn't offer any reflection API to see the default values of static variables. (This is primarily a problem for ext-pthreads class copying.)

Test script:

class Statics{
	public static $staticVar = 1;

Statics::$staticVar = 2;

$reflect = new \ReflectionClass(Statics::class);
$prop = $reflect->getProperty("staticVar");

Expected result:

Actual result:
WITH OPcache:



Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 13 06:01:23 2021 UTC