Posted by Jerry Stuckle on 09/12/07 12:13
Yarco wrote:
> For example:
>
> <?php
> class Test
> {
> private $name = 'yarco';
> }
>
> $p = new ReflectionPropery('Test', 'name');
> print $p->getValue();
>
> ?>
>
> This won't work. See: http://www.php.net/manual/en/language.oop5.reflection.php
> ==================
> Note: Trying to get or set private or protected class property's
> values will result in an exception being thrown.
> ==================
> But when we use print_r or var_dump, we could see the private member.
> Why reflection doesn't support this?
> (We have friend class in c++.)
>
Because that's the way it works. And there are no friend classes in PHP.
If you want the value of a private variable, you need a non-private
method to get it.
And I suspect the allow print_r() and var_dump() to display the values
because those are debugging aids, while reflection isn't necessarily.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|