Bug #80821 [Opn->Csd]: ReflectionProperty::getDefaultValue() returns current value for statics
| From: | nikic@php.net | Date: | Fri, 23 Jul 2021 07:30:29 +0000 |
| Subject: | Bug #80821 [Opn->Csd]: ReflectionProperty::getDefaultValue() returns current value for statics | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235270@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80821&edit=1
ID: 80821
Updated by: nikic@php.net
Reported by: dktapps at pmmp dot io
Summary: ReflectionProperty::getDefaultValue() returns
current value for statics
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: Linux
PHP Version: 8.0.2
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed by https://github.com/php/php-src/commit/3eb97a456648c739533d92c81102cb919eab01c9.
Previous Comments:
------------------------------------------------------------------------
[2021-03-02 23:17:25] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80821&edit=1