Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96027 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35025 invoked from network); 19 Sep 2016 08:38:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2016 08:38:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=stoller@leonex.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stoller@leonex.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain leonex.de designates 80.87.117.30 as permitted sender) X-PHP-List-Original-Sender: stoller@leonex.de X-Host-Fingerprint: 80.87.117.30 office.int.leonex.de Received: from [80.87.117.30] ([80.87.117.30:44827] helo=office.int.leonex.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/09-19521-FF3AFD75 for ; Mon, 19 Sep 2016 04:38:23 -0400 Received: from ex-srv1.ameusgmbh.intern ([192.168.222.212]:42524 helo=owa.int.leonex.de) by office.int.leonex.de with esmtps (TLSv1.2:AES256-SHA256:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1blu5h-0003Y1-2h for internals@lists.php.net; Mon, 19 Sep 2016 10:38:18 +0200 Received: from (127.0.0.1) by ex-srv1.ameusgmbh.intern (127.0.0.1) with Microsoft SMTP Server id 15.1.466.34; Mon, 19 Sep 2016 10:38:17 +0200 Received: from ex-srv1.ameusgmbh.intern (192.168.222.212) by ex-srv1.ameusgmbh.intern (192.168.222.212) with Microsoft SMTP Server (TLS) id 15.1.466.34; Mon, 19 Sep 2016 10:38:16 +0200 Received: from ex-srv1.ameusgmbh.intern ([fe80::38fc:4042:690c:8aec]) by ex-srv1.ameusgmbh.intern ([fe80::38fc:4042:690c:8aec%12]) with mapi id 15.01.0466.037; Mon, 19 Sep 2016 10:38:16 +0200 X-CTCH-RefID: str=0001.0A0C0204.57DFA3FA.000C,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 To: "internals@lists.php.net" Thread-Topic: Problem with overwriting private property value with ReflectionProperty Thread-Index: AdISUNEOwdAi6BbdQKecQT2inUaPKQ== Date: Mon, 19 Sep 2016 08:38:16 +0000 Message-ID: Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.222.112] x-ci-mailpolicy-key: 3afdb155176f1c9b71806b2b620f0c96 Content-Type: multipart/alternative; boundary="_000_MP379B933D000607a8bfee4762864dc1917052cb0ca9ede9leonexd_" MIME-Version: 1.0 Subject: Re: Problem with overwriting private property value with ReflectionProperty From: stoller@leonex.de (Christian Stoller) --_000_MP379B933D000607a8bfee4762864dc1917052cb0ca9ede9leonexd_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Von: Christian Stoller [mailto:stoller@leonex.de], Gesendet: Montag, 19. Se= ptember 2016 10:27 Betreff: [PHP-DEV] Problem with overwriting private property value with Ref= lectionProperty > 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 =3D 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 valu= e 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 array. Sorry for the noise. Christian Mit freundlichen Gr??en aus Paderborn Christian Stoller Softwareentwicklung 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 ________________________________ --_000_MP379B933D000607a8bfee4762864dc1917052cb0ca9ede9leonexd_--