Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43622 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89162 invoked from network); 4 Apr 2009 11:08:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2009 11:08:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=r.borschel@gmx.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=r.borschel@gmx.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.net designates 213.165.64.20 as permitted sender) X-PHP-List-Original-Sender: r.borschel@gmx.net X-Host-Fingerprint: 213.165.64.20 mail.gmx.net Linux 2.6 Received: from [213.165.64.20] ([213.165.64.20:60752] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/5B-01679-EAF37D94 for ; Sat, 04 Apr 2009 06:08:31 -0500 Received: (qmail invoked by alias); 04 Apr 2009 11:08:26 -0000 Received: from e178172176.adsl.alicedsl.de (EHLO [192.168.0.43]) [85.178.172.176] by mail.gmx.net (mp037) with SMTP; 04 Apr 2009 13:08:26 +0200 X-Authenticated: #13379417 X-Provags-ID: V01U2FsdGVkX1/3FIxYEQP3BGWK2nOWL1CU7/M+jDSiCegugC7adP IJk3mQbK0T4+be Cc: =?ISO-8859-1?Q?Johannes_Schl=FCter?= , PHP Developers Mailing List Message-ID: To: Roman Borschel In-Reply-To: <594A574F-E6B2-4FDD-92D3-4492D0DD2A5D@gmx.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v930.3) Date: Sat, 4 Apr 2009 13:08:26 +0200 References: <2FA0A495-EC1A-4C51-9EE6-F9680D9FD114@gmx.net> <1238802796.5741.1.camel@goldfinger> <11478D41-777A-42BC-9CE7-105FFFEA4B74@gmx.net> <594A574F-E6B2-4FDD-92D3-4492D0DD2A5D@gmx.net> X-Mailer: Apple Mail (2.930.3) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.46 Subject: Re: [PHP-DEV] Private properties, Inheritance, Reflection (5.3) From: r.borschel@gmx.net (Roman Borschel) Hi, Despite my almost non-existant C-skills I managed to put together a =20 "patch" (or what I think is a patch) that does not break any tests. My "patch" is simply to replace the first argument of =20 zend_update_property/zend_read_property in ext/php_reflection.c like =20 this: within the getValue definition: old: member_p =3D zend_read_property(Z_OBJCE_P(object), object, =20 prop_name, strlen(prop_name), 1 TSRMLS_CC); new: member_p =3D zend_read_property(ref->ce, object, prop_name, =20 strlen(prop_name), 1 TSRMLS_CC); within the setValue definition: old: zend_update_property(Z_OBJCE_P(object), object, prop_name, =20 strlen(prop_name), value TSRMLS_CC); new: zend_update_property(ref->ce, object, prop_name, =20 strlen(prop_name), value TSRMLS_CC); So simply replacing Z_OBJCE_P(object) with ref->ce. I assume "ce" stands for "class entry" and is a zend_class_entry. So =20 instead of taking the zend_class_entry from the object, we take the =20 one associated with the reflection property (at least thats what i =20 assume it does). I will now try to create a new test for this issue, taking of the =20 existing tests as a template. Any comments appreciated. Roman On Apr 4, 2009, at 9:02 AM, Roman Borschel wrote: > For what it matters, the same thing in Java returns the expected =20 > result: > > Class clazz =3D Foo.class; > Field fooProp =3D clazz.getDeclaredField("foo"); > fooProp.setAccessible(true); > Bar bar =3D new Bar(); > String value =3D (String)fooProp.get(bar); > System.out.println(value); > > So is this a bug or some weird behavior I just don't understand yet? > > Roman > > On Apr 4, 2009, at 7:34 AM, Roman Borschel wrote: > >> Hi, >> >> On Apr 4, 2009, at 1:53 AM, Johannes Schl=FCter wrote: >> >>> On Fri, 2009-04-03 at 22:37 +0200, Roman Borschel wrote: >>>> Given the following simple classes >>>> >>>> class Foo { >>>> private $foo =3D 'value'; >>>> public function getFoo() { return $this->foo; } >>>> } >>>> class Bar extends Foo {} >>>> >>>> Obviously, given an instance of Bar, say $bar, $bar->getFoo() =20 >>>> returns >>>> 'value'. >>>> >>>> Now the question: How do I get at this value using reflection, =20 >>>> given >>>> an instance of Bar? >>> >>> class Foo { private $foo =3D "value"; } >>> class Bar extends Foo {} >>> $f =3D new Foo; >>> // we have to know the context, as there might be multiple foo =20 >>> properties >>> $r =3D new ReflectionProperty("Foo", "foo"); >>> $r->setAccessible(true); >>> var_dump($r->getValue($f)); >>> >>> works for me. >>> >>> johannes >> >> Thanks for your answer. Yes, this works, but here $f is an instance =20= >> of Foo, not Bar. When you make it an instance of Bar you get NULL. =20= >> I think this is not correct, is it? >> Given that we have a ReflectionProperty of class Foo at hand, from =20= >> my understanding it should look at an instance of Bar as a Foo and =20= >> return the value. Am I missing something? >> >> Regards >> >> Roman >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php