• <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 反射类.如何获取属性的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <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>