I have spent several hours with a strange problem with reflection.

There's an object of an external lib with a private field and I have to 
overwrite its values. Because there is no public method I am using 
ReflectionProperty like this:

$reflProp = new \ReflectionProperty(Extension::class, 'classes');
$reflProp->setValue($extension,['new', 'values']);


The field is of type array and contains several entries. The problem is, that 
the private field has not been overwritten by `$reflProp->setValue()`. Instead 
it looked like, the array of the private field has been merged with my new 

I tried different things but nothing worked. I have tried to create a small 
script which could show the problem, but it wasn't reproducible.

The last thing I tried was, to call


instead of


That returns exactly the correct value. So my question is if somebody could 
imagine why `$reflProp->getValue()` returns the value I am trying to set, but 
accessing the field with an object member method (getClasses) returns a merged 

I am using PHP 5.6.26 (x86, TS) on Windows 10.

Best regards,

Mit freundlichen Gr??en aus Paderborn

Christian Stoller

LEONEX Internet GmbH
Technologiepark 20
33100 Paderborn
Tel: 05251-14807-27
Fax: 05251-14807-30
HRB 8694 AG Paderborn
Gesch?ftsf?hrer: Stephan Winter

Erfolgreiche E-Business L?sungen von LEONEX
Erfahren Sie mehr unter www.leonex.de

Reply via email to