<i id='QAFWI'><tr id='QAFWI'><dt id='QAFWI'><q id='QAFWI'><span id='QAFWI'><b id='QAFWI'><form id='QAFWI'><ins id='QAFWI'></ins><ul id='QAFWI'></ul><sub id='QAFWI'></sub></form><legend id='QAFWI'></legend><bdo id='QAFWI'><pre id='QAFWI'><center id='QAFWI'></center></pre></bdo></b><th id='QAFWI'></th></span></q></dt></tr></i><div id='QAFWI'><tfoot id='QAFWI'></tfoot><dl id='QAFWI'><fieldset id='QAFWI'></fieldset></dl></div>
    <bdo id='QAFWI'></bdo><ul id='QAFWI'></ul>

<small id='QAFWI'></small><noframes id='QAFWI'>

  • <tfoot id='QAFWI'></tfoot>

      1. <legend id='QAFWI'><style id='QAFWI'><dir id='QAFWI'><q id='QAFWI'></q></dir></style></legend>

        我可以通过 Reflection 获取私有财产的价值吗?

        时间:2023-09-22
        <i id='jGDsH'><tr id='jGDsH'><dt id='jGDsH'><q id='jGDsH'><span id='jGDsH'><b id='jGDsH'><form id='jGDsH'><ins id='jGDsH'></ins><ul id='jGDsH'></ul><sub id='jGDsH'></sub></form><legend id='jGDsH'></legend><bdo id='jGDsH'><pre id='jGDsH'><center id='jGDsH'></center></pre></bdo></b><th id='jGDsH'></th></span></q></dt></tr></i><div id='jGDsH'><tfoot id='jGDsH'></tfoot><dl id='jGDsH'><fieldset id='jGDsH'></fieldset></dl></div>
          <tbody id='jGDsH'></tbody>
          <tfoot id='jGDsH'></tfoot>
          <legend id='jGDsH'><style id='jGDsH'><dir id='jGDsH'><q id='jGDsH'></q></dir></style></legend>
          • <small id='jGDsH'></small><noframes id='jGDsH'>

                • <bdo id='jGDsH'></bdo><ul id='jGDsH'></ul>
                  本文介绍了我可以通过 Reflection 获取私有财产的价值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  它似乎不起作用:

                  $ref = new ReflectionObject($obj);
                  
                  if($ref->hasProperty('privateProperty')){
                    print_r($ref->getProperty('privateProperty'));
                  }
                  

                  它进入IF循环,然后抛出一个错误:

                  It gets into the IF loop, and then throws an error:

                  属性 privateProperty 不存在

                  Property privateProperty does not exist

                  :|

                  $ref = new ReflectionProperty($obj, 'privateProperty') 也不起作用...

                  文档页面列出了一些常量,包括 IS_PRIVATE.如果我无法访问私有财产,我怎么能使用它呢?

                  The documentation page lists a few constants, including IS_PRIVATE. How can I ever use that if I can't access a private property lol?

                  推荐答案

                  class A
                  {
                      private $b = 'c';
                  }
                  
                  $obj = new A();
                  
                  $r = new ReflectionObject($obj);
                  $p = $r->getProperty('b');
                  $p->setAccessible(true); // <--- you set the property to public before you read the value
                  
                  var_dump($p->getValue($obj));
                  

                  这篇关于我可以通过 Reflection 获取私有财产的价值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我的 PHP 应用程序是否正确支持 UTF-8? 下一篇:PHP 反射 - 获取方法参数类型为字符串

                  相关文章

                  最新文章

                • <legend id='QECnp'><style id='QECnp'><dir id='QECnp'><q id='QECnp'></q></dir></style></legend>

                      <bdo id='QECnp'></bdo><ul id='QECnp'></ul>
                    <tfoot id='QECnp'></tfoot>
                  1. <i id='QECnp'><tr id='QECnp'><dt id='QECnp'><q id='QECnp'><span id='QECnp'><b id='QECnp'><form id='QECnp'><ins id='QECnp'></ins><ul id='QECnp'></ul><sub id='QECnp'></sub></form><legend id='QECnp'></legend><bdo id='QECnp'><pre id='QECnp'><center id='QECnp'></center></pre></bdo></b><th id='QECnp'></th></span></q></dt></tr></i><div id='QECnp'><tfoot id='QECnp'></tfoot><dl id='QECnp'><fieldset id='QECnp'></fieldset></dl></div>
                    1. <small id='QECnp'></small><noframes id='QECnp'>