Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43619 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24507 invoked from network); 3 Apr 2009 23:53:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2009 23:53:26 -0000 Authentication-Results: pb1.pair.com header.from=johannes@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 83.243.58.134 as permitted sender) X-PHP-List-Original-Sender: johannes@php.net X-Host-Fingerprint: 83.243.58.134 mailout2.netbeat.de Linux 2.6 Received: from [83.243.58.134] ([83.243.58.134:34625] helo=mailout2.netbeat.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/B3-01679-471A6D94 for ; Fri, 03 Apr 2009 18:53:26 -0500 Received: (qmail 11155 invoked by uid 89); 4 Apr 2009 00:18:37 -0000 Received: from unknown (HELO ?192.168.1.101?) (johannes%schlueters.de@88.217.61.230) by mailout2.netbeat.de with ESMTPA; 4 Apr 2009 00:18:37 -0000 To: Roman Borschel Cc: PHP Developers Mailing List In-Reply-To: <2FA0A495-EC1A-4C51-9EE6-F9680D9FD114@gmx.net> References: <2FA0A495-EC1A-4C51-9EE6-F9680D9FD114@gmx.net> Content-Type: text/plain Date: Sat, 04 Apr 2009 01:53:16 +0200 Message-ID: <1238802796.5741.1.camel@goldfinger> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Private properties, Inheritance, Reflection (5.3) From: johannes@php.net (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Fri, 2009-04-03 at 22:37 +0200, Roman Borschel wrote: > Given the following simple classes > > class Foo { > private $foo = '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 = "value"; } class Bar extends Foo {} $f = new Foo; // we have to know the context, as there might be multiple foo properties $r = new ReflectionProperty("Foo", "foo"); $r->setAccessible(true); var_dump($r->getValue($f)); works for me. johannes