Bug #80821 [NEW]: ReflectionProperty::getDefaultValue() returns current value for statics
| From: | dktapps at pmmp dot io | Date: | Tue, 02 Mar 2021 23:17:25 +0000 |
| Subject: | Bug #80821 [NEW]: ReflectionProperty::getDefaultValue() returns current value for statics | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232483@lists.php.net to get a copy of this message | ||
From: dktapps at pmmp dot io
Operating system: Linux
PHP version: 8.0.2
Package: Reflection related
Bug Type: Bug
Bug description:ReflectionProperty::getDefaultValue() returns current value for statics
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 bug report at https://bugs.php.net/bug.php?id=80821&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80821&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80821&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80821&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80821&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80821&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80821&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80821&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80821&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80821&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80821&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80821&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80821&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80821&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80821&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80821&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80821&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80821&r=mysqlcfg