Is there any way to set a private/protected static property using reflection classes?

后端 未结 2 1419
广开言路
广开言路 2020-12-24 00:31

I am trying to perform a backup/restore function for static properties of classes. I can get a list of all of the static properties and their values using the reflection obj

2条回答
  •  盖世英雄少女心
    2020-12-24 01:05

    For accessing private/protected properties of a class, using reflection, without the need for a ReflectionObject instance:

    For static properties:

    setAccessible(true);
    $reflection->setValue(null, 'new property value');
    


    For non-static properties:

    setAccessible(true);
    $reflection->setValue($instance, 'new property value');
    

提交回复
热议问题