Von: Christian Stoller [mailto:stol...@leonex.de], Gesendet: Montag, 19. 
September 2016 10:27
Betreff: [PHP-DEV] Problem with overwriting private property value with 

> Hi,
> 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->setAccessible(true);
> $reflProp->setValue($extension,['new', 'values']);
> var_export($extension->getClasses());
> 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
> var_export($reflProp->getValue($extension));
> instead of
> var_export($extension->getClasses());
> 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,
> Christian

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

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