如何获得私人会员的价值? [英] How to get value of an private member?
问题描述
例如:
<?php
class Test
{
private $ name =''yarco'';
}
$ p = new ReflectionPropery(''Test'',''name'');
打印$ p-> getValue();
?>
这不行。请参阅: http://www.php.net/ manual / en / languag ... reflection.php
==================
注意:尝试获取或设置私有或受保护的类属性'
值将导致抛出异常。
=========== =======
但是当我们使用print_r或var_dump时,我们可以看到私人成员。
为什么反射不支持这个?
(我们在c ++中有朋友类。)
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/languag...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++.)
推荐答案
name =''yarco'';
}
name = ''yarco'';
}
p = new ReflectionPropery(''Test'',''name'');
p = new ReflectionPropery(''Test'', ''name'');
p-> getValue();
?>
这赢了不行。请参阅: http://www.php.net/ manual / en / languag ... reflection.php
==================
注意:尝试获取或设置私有或受保护的类属性'
值将导致抛出异常。
=========== =======
但是当我们使用print_r或var_dump时,我们可以看到私人成员。
为什么反射不支持这个?
(我们在c ++中有朋友类。)
p->getValue();
?>
This won''t work. See: http://www.php.net/manual/en/languag...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++.)
这篇关于如何获得私人会员的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!