• <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 中的动态属性(设置未声明的属性时引发错误)

        How to avoid dynamic properties in PHP (raise an Error when setting an undeclared property)(如何避免 PHP 中的动态属性(设置未声明的属性时引发错误))
          <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 中的动态属性(设置未声明的属性时引发错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(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>
                        <tbody id='DK5za'></tbody>

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

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