Hi,

i've got a little question that involves private properties, inheritance and Reflection with PHP 5.3 RC1.

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 = new \ReflectionClass('Foo');
$fooProp = $class->getProperty('foo');
$fooProp->setAccessible(true);
$bar = new Bar;
$value = $fooProp->getValue($bar);
var_dump($value); // NULL
var_dump($bar); // array(1) { ["�Foo�foo"]=>  string(5) "value" }

How do I get at the value exposed by "var_dump($bar);" through reflection?
Obviously, I can't upcast like this: "$fooProp->getValue((Foo)$bar)".

I'm asking here because I have the bad feeling that this is might not (yet?) be possible.

Thanks!

Roman
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to