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

From: Date: Fri, 23 Jul 2021 08:00:46 +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-235275@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:

After https://github.com/php/php-src/commit/3eb97a456648c739533d92c81102cb919eab01c9
the behavior will be consistently "a a" as previously with opcache, and in line with the
docs.

We could still change the behavior and docs though.


Previous Comments:
------------------------------------------------------------------------
[2020-07-14 17:46:40] stsalkov at gmail dot com

Since this behavior dates back to PHP 4, I think it'd be fair to say "the documentation is
wrong" rather than "the implementation is wrong." To me, the culture of not breaking
backwards compatibility has always been an important part of PHP.

In any case, it shouldn't behave differently depending on whether opcache is enabled.

------------------------------------------------------------------------
[2020-07-13 08:20:53] nikic@php.net

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.

------------------------------------------------------------------------
[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

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=79822


--
Edit this bug report at https://bugs.php.net/bug.php?id=79822&edit=1


Thread (8 messages)

« previous php.bugs (#235275) next »