如何获得私人会员的价值? [英] How to get value of an private member?

查看:72
本文介绍了如何获得私人会员的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:


<?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'');

print
p = new ReflectionPropery(''Test'', ''name'');
print


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆