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

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

    1. <small id='jpPkc'></small><noframes id='jpPkc'>

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

        如何避免 PHP 中的动态属性(设置未声明的属性时引发错误)

        时间:2023-08-20
          <tfoot id='SFt2U'></tfoot>
          • <small id='SFt2U'></small><noframes id='SFt2U'>

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

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

                  本文介绍了如何避免 PHP 中的动态属性(设置未声明的属性时引发错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  示例:

                  error_reporting(E_ALL | E_STRICT);
                  class Test {}
                  $obj = new Test();
                  $obj->undeclared = "oops";    // I want an error here !! :(
                  echo $obj->algo;              // oops 
                  

                  我在 PHP 5.2.11 和 5.3.0 上测试过.

                  I tested it on PHP 5.2.11 and 5.3.0.

                  我不想在我的对象中使用动态属性.
                  在这种情况下可以强制 PHP 引发 ERROR 吗?

                  I don't want dynamic properties in my objects.
                  Is possible to force PHP to raise an ERROR in that situation ?

                  推荐答案

                  使用 __set() ?

                  <?php
                  class Test {
                  
                      public $bar;
                  
                      public function __set($name, $value) {
                          throw new Exception('Cant set!');
                      }
                  }
                  
                  $obj = new Test;
                  $obj->bar = 'foo';
                  $obj->foo = 'evil';
                  ?>
                  

                  这篇关于如何避免 PHP 中的动态属性(设置未声明的属性时引发错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:php中的动态类属性$$value 下一篇:php 后台 exec() 函数

                  相关文章

                  <tfoot id='DK5za'></tfoot>
                    <bdo id='DK5za'></bdo><ul id='DK5za'></ul>

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

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

                    2. <small id='DK5za'></small><noframes id='DK5za'>