php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
40 + 40 = ?
Subscribe to this entry?

 
 [2021-03-02 23:17 UTC] dktapps at pmmp dot io
Description:
------------
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:
---------------
<?php

class Statics{
	public static $staticVar = 1;
}

Statics::$staticVar = 2;

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


Expected result:
----------------
int(1)

Actual result:
--------------
WITH OPcache:
int(1)

WITHOUT OPcache:
int(2)

Patches

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