Bug #79822 [Ver]: Opcache and get_class_vars() - first output correct, subsequent outputs wrong

From: Date: Mon, 13 Jul 2020 08:20:53 +0000
Subject: Bug #79822 [Ver]: Opcache and get_class_vars() - first output correct, subsequent outputs wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227988@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79822&edit=1 ID: 79822 Updated by: nikic@php.net Reported by: wadih at systemesmw dot com Summary: Opcache and get_class_vars() - first output correct, subsequent outputs wrong Status: Verified Type: Bug Package: opcache Operating System: Ubuntu PHP Version: 7.4.3 Block user comment: N Private report: N New Comment: What is the expected behavior here? The docs say: > Returns an associative array of declared properties visible from the current scope, with their > default value. The resulting array elements are in the form of varname => value. In case of an > error, it returns FALSE. So based on that, and what the implementation does, the intention here was to return the default values, not the current values. However, historically we don't even remember the default values of static properties! In 7.4 we do if opcache is loaded, thus the change in behavior. ReflectionClass::getDefaultProperties() is probably also affected. Previous Comments: ------------------------------------------------------------------------ [2020-07-09 16:57:54] cmb@php.net With the most recent PHP-7.4 from Git, I get the wrong result on CLI (Windows) with OPcache enabled right away on the first run. This may have the same root cause as bug #79487. ------------------------------------------------------------------------ [2020-07-09 13:56:12] stsalkov at gmail dot com Can confirm this on a vanilla Ubuntu 20.04LTS install (Apache/2.4.41, PHP 7.4.3). ------------------------------------------------------------------------ [2020-07-09 13:44:49] wadih at systemesmw dot com update summary ------------------------------------------------------------------------ [2020-07-09 13:42:46] wadih at systemesmw dot com Description: ------------ The same call to get_class_vars() prints different values depending if it's the first time I run it, or if it's subsequent times, when opcache is on which is on by default. (See code in Test script) First time, e.g. http://localhost/mytest.php, it prints: 7.4.3 Array ( [v] => a ) Array ( [v] => b ) Refresh the page, now prints: 7.4.3 Array ( [v] => a ) Array ( [v] => a ) Any subsequent refreshes prints [v] => a Now slightly modify the PHP page to trigger a change , and it prints: 7.4.3 Array ( [v] => a ) Array ( [v] => b ) Refresh the page, and goes back to: 7.4.3 Array ( [v] => a ) Array ( [v] => a ) And subsequent refreshes still print [v] => a SOLUTION: Set opcache.enable=0 in php.ini, restart apache2. Bug disappears, and prints [v] => b each time now. VERSIONS: Apache/2.4.41 (Ubuntu) PHP 7.4.3 (cli) libapache2-mod-php 2:7.4+75 Test script: --------------- class MyClass { public static $v = 'a'; } echo '<pre>'; echo phpversion() . "\n"; print_r(get_class_vars('MyClass')); MyClass::$v = 'b'; print_r(get_class_vars('MyClass')); Expected result: ---------------- 7.4.3 Array ( [v] => a ) Array ( [v] => b ) Actual result: -------------- 7.4.3 Array ( [v] => a ) Array ( [v] => a ) // Note, it is correct only first time it is run, but wrong all subsequent times, when opcache is active ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79822&edit=1

« previous php.bugs (#227988) next »