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

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

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

          <bdo id='QHGw1'></bdo><ul id='QHGw1'></ul>

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

        PHP 反射类.如何获取属性的值?

        PHP Reflection Class. How to get the values of the properties?(PHP 反射类.如何获取属性的值?)
        <i id='Xbbp5'><tr id='Xbbp5'><dt id='Xbbp5'><q id='Xbbp5'><span id='Xbbp5'><b id='Xbbp5'><form id='Xbbp5'><ins id='Xbbp5'></ins><ul id='Xbbp5'></ul><sub id='Xbbp5'></sub></form><legend id='Xbbp5'></legend><bdo id='Xbbp5'><pre id='Xbbp5'><center id='Xbbp5'></center></pre></bdo></b><th id='Xbbp5'></th></span></q></dt></tr></i><div id='Xbbp5'><tfoot id='Xbbp5'></tfoot><dl id='Xbbp5'><fieldset id='Xbbp5'></fieldset></dl></div>

                <tbody id='Xbbp5'></tbody>

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

            • <legend id='Xbbp5'><style id='Xbbp5'><dir id='Xbbp5'><q id='Xbbp5'></q></dir></style></legend>
                <tfoot id='Xbbp5'></tfoot>

                • <bdo id='Xbbp5'></bdo><ul id='Xbbp5'></ul>
                • 本文介绍了PHP 反射类.如何获取属性的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 PHP 中使用反射类,但我不知道如何获取反射实例中的属性值.有可能吗?

                  I'm using the reflection class in PHP, but I'm with no clues on how to get the values of the properties in the reflection instance. It is possible?

                  代码:

                  <?php
                  
                  class teste {
                  
                      public $name;
                      public $age;
                  
                  }
                  
                  $t = new teste();
                  $t->name = 'John';
                  $t->age = '23';
                  
                  $api = new ReflectionClass($t);
                  
                  foreach($api->getProperties() as $propertie)
                  {
                      print $propertie->getName() . "
                  ";
                  }
                  
                  ?>
                  

                  如何获取 foreach 循环内的属性值?

                  How can I get the propertie values inside the foreach loop?

                  此致,

                  推荐答案

                  怎么样

                  • ReflectionProperty::getValue - 获取属性值.

                  就你而言:

                  foreach ($api->getProperties() as $propertie)
                  {
                      print $propertie->getName() . "
                  ";
                      print $propertie->getValue($t);
                  }
                  

                  顺便说一句,因为你的对象只有公共成员,你也可以迭代它直接

                  On a sidenote, since your object has only public members, you could just as well iterate it directly

                  foreach ($t as $propertie => $value)
                  {
                      print $propertie . "
                  ";
                      print $value;
                  }
                  

                  或使用 get_object_vars 获取它们一个数组.

                  or fetch them with get_object_vars into an array.

                  这篇关于PHP 反射类.如何获取属性的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                    <bdo id='tmR0p'></bdo><ul id='tmR0p'></ul>

                    • <small id='tmR0p'></small><noframes id='tmR0p'>

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

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