Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43620 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51120 invoked from network); 4 Apr 2009 05:34:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Apr 2009 05:34:17 -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:58680] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/E5-01679-851F6D94 for ; Sat, 04 Apr 2009 00:34:17 -0500 Received: (qmail invoked by alias); 04 Apr 2009 05:34:12 -0000 Received: from e178172176.adsl.alicedsl.de (EHLO [192.168.0.43]) [85.178.172.176] by mail.gmx.net (mp003) with SMTP; 04 Apr 2009 07:34:13 +0200 X-Authenticated: #13379417 X-Provags-ID: V01U2FsdGVkX1+4868s+DS4C4RxrnLGuhQwDv1QAH7IvKxl9u3q0u W3ACDOSwmNGrjg Cc: PHP Developers Mailing List Message-ID: <11478D41-777A-42BC-9CE7-105FFFEA4B74@gmx.net> To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= In-Reply-To: <1238802796.5741.1.camel@goldfinger> 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 07:34:09 +0200 References: <2FA0A495-EC1A-4C51-9EE6-F9680D9FD114@gmx.net> <1238802796.5741.1.camel@goldfinger> X-Mailer: Apple Mail (2.930.3) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.5 Subject: Re: [PHP-DEV] Private properties, Inheritance, Reflection (5.3) From: r.borschel@gmx.net (Roman Borschel) 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() returns >> 'value'. >> >> Now the question: How do I get at this value using reflection, 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 of =20= Foo, not Bar. When you make it an instance of Bar you get NULL. I =20 think this is not correct, is it? Given that we have a ReflectionProperty of class Foo at hand, from my =20= understanding it should look at an instance of Bar as a Foo and return =20= the value. Am I missing something? Regards Roman