1

I have this simple code that demonstrates updating a static value:

<?php

class myClass
{
    // empty static var
    public static $prop1;

}

myClass::$prop1 = array("Hey, I'm setting your value now");
var_dump(myClass::$prop1);

$allVars = get_class_vars( myClass::class ) ;
var_dump ( $allVars );

So I'm expecting both dumps to show the new value. While it works perfectly when (opcache) not enabled. But then it gives a bizarre output when (opcache) is enabled..

Is there any config responsible about this behavior ?

PHP 7.4.14

1-PHP 7.4.14 without opcache.so (OK)

 array (size=1)   0 =>
 string 'Hey, I'm setting your value now' (length=31)
 
 array (size=1)   'prop1'
 => 
     array (size=1)
       0 => string 'Hey, I'm setting your value now' (length=31)

2-PHP 7.4.14 with opcache.so enabled (Not ok, odd)

 array(1) {   [0]=>   string(31) "Hey, I'm setting your value now" }  
 array(1) {   ["prop1"]=>   NULL }

What do you think ?

Aproram
  • 348
  • 1
  • 3
  • 16
  • 1
    Interesting question. Has been reported [here](https://bugs.php.net/bug.php?id=79822&edit=1). – SirPilan Jan 23 '21 at 22:29
  • It turns out that the result given when OpCache was on was actually the documented one: return the *default* value of the property, not the *current* one. In newer versions of PHP, this is the consistent result. – IMSoP Jan 09 '23 at 17:45

0 Answers0