Von: Christian Stoller [mailto:stol...@leonex.de], Gesendet: Montag, 19.
September 2016 10:27
Betreff: [PHP-DEV] Problem with overwriting private property value with
> 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 array.
> 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 array.
> I am using PHP 5.6.26 (x86, TS) on Windows 10.
> Best regards,
Oh, sorry. I have found the problem now, after trying to overwrite the value
with a string instead of an array. The object I had the problem with, has been
extended by another class the the `getClasses` merged the field with another
Sorry for the noise.
Mit freundlichen Gr??en aus Paderborn
LEONEX Internet GmbH
HRB 8694 AG Paderborn
Gesch?ftsf?hrer: Stephan Winter
Erfolgreiche E-Business L?sungen von LEONEX
Erfahren Sie mehr unter www.leonex.de