pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<small id='2Hims'></small><noframes id='2Hims'>

<legend id='2Hims'><style id='2Hims'><dir id='2Hims'><q id='2Hims'></q></dir></style></legend>

  • <tfoot id='2Hims'></tfoot>
    1. <i id='2Hims'><tr id='2Hims'><dt id='2Hims'><q id='2Hims'><span id='2Hims'><b id='2Hims'><form id='2Hims'><ins id='2Hims'></ins><ul id='2Hims'></ul><sub id='2Hims'></sub></form><legend id='2Hims'></legend><bdo id='2Hims'><pre id='2Hims'><center id='2Hims'></center></pre></bdo></b><th id='2Hims'></th></span></q></dt></tr></i><div class="fu3bwrp" id='2Hims'><tfoot id='2Hims'></tfoot><dl id='2Hims'><fieldset id='2Hims'></fieldset></dl></div>

        <bdo id='2Hims'></bdo><ul id='2Hims'></ul>

        致命錯誤:不在對象上下文中時使用 $this

        Fatal error: Using $this when not in object context in(致命錯誤:不在對象上下文中時使用 $this)

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

              <bdo id='SG0vh'></bdo><ul id='SG0vh'></ul>
                <tbody id='SG0vh'></tbody>
              • <legend id='SG0vh'><style id='SG0vh'><dir id='SG0vh'><q id='SG0vh'></q></dir></style></legend>

                <tfoot id='SG0vh'></tfoot>

                1. <i id='SG0vh'><tr id='SG0vh'><dt id='SG0vh'><q id='SG0vh'><span id='SG0vh'><b id='SG0vh'><form id='SG0vh'><ins id='SG0vh'></ins><ul id='SG0vh'></ul><sub id='SG0vh'></sub></form><legend id='SG0vh'></legend><bdo id='SG0vh'><pre id='SG0vh'><center id='SG0vh'></center></pre></bdo></b><th id='SG0vh'></th></span></q></dt></tr></i><div class="l0xls0r" id='SG0vh'><tfoot id='SG0vh'></tfoot><dl id='SG0vh'><fieldset id='SG0vh'></fieldset></dl></div>
                  本文介紹了致命錯誤:不在對象上下文中時使用 $this的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有這個類用于使用 php/mysqli 連接到 mysql 數據庫:

                  class AuthDB {私人 $_db;公共函數 __construct() {$this->_db = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME)or die("連接數據庫有問題.錯誤:".mysqli_error());}公共函數 __destruct() {$this->_db->close();未設置($this->_db);}}

                  現在,我有列表用戶的任何頁面:

                  require_once 'classes/AuthDB.class.php';session_start();$this->_db = new AuthDB();//這條線的錯誤$query = "SELECT Id, user_salt, password, is_active, is_verified FROM Users where email = ?";$stmt = $this->_db->prepare($query);//綁定參數$stmt->bind_param("s", $email);//執行語句如果 ($stmt->execute()) {//綁定結果列$stmt->bind_result($id, $salt, $pass, $active, $ver);//獲取第一行結果$stmt->fetch();回聲 $id;}

                  現在,我看到這個錯誤:

                  致命錯誤:第 6 行中不在對象上下文中時使用 $this

                  如何修復這個錯誤?!

                  解決方案

                  就像錯誤所說的那樣,您不能在類定義之外使用 $this.要在類定義之外使用 $_db,首先將其設為 public 而不是 private:

                  public $_db

                  然后,使用此代碼:

                  $authDb = new AuthDb();$authDb->_db->prepare($query);//其余代碼相同

                  --

                  您必須了解 $this 的實際含義.在類定義中使用時,$this 用于引用該類的對象.因此,如果您在 AuthDB 中有一個函數 foo,并且您需要從 foo 內訪問 $_db,您將使用 $this 告訴 PHP 您想要 $_db 來自 foo 所屬的同一對象.

                  您可能想閱讀這個 StackOverflow 問題:PHP:self vs $this>

                  i have this class for connect to mysql database using php/mysqli:

                  class AuthDB {
                      private $_db;
                  
                      public function __construct() {
                          $this->_db = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME)
                          or die("Problem connect to db. Error: ". mysqli_error());
                      }
                  
                      public function __destruct() {
                          $this->_db->close();
                          unset($this->_db);
                      }
                  }
                  

                  now, i have any page for list user :

                  require_once 'classes/AuthDB.class.php';
                  
                  session_start();
                  
                  $this->_db = new AuthDB(); // error For This LINE
                  $query = "SELECT Id, user_salt, password, is_active, is_verified FROM Users where email = ?";
                  $stmt = $this->_db->prepare($query);
                  
                          //bind parameters
                          $stmt->bind_param("s", $email);
                  
                          //execute statements
                          if ($stmt->execute()) {
                              //bind result columnts
                              $stmt->bind_result($id, $salt, $pass, $active, $ver);
                  
                              //fetch first row of results
                              $stmt->fetch();
                  
                              echo $id;
                  
                  
                          }
                  

                  now, i see this error:

                  Fatal error: Using $this when not in object context in LINE 6
                  

                  How to fix this error?!

                  解決方案

                  Like the error says, you can't use $this outside of the class definition. To use $_db outside the class definition, first make it public instead of private:

                  public $_db

                  Then, use this code:

                  $authDb = new AuthDb();
                  $authDb->_db->prepare($query); // rest of code is the same
                  

                  --

                  You have to understand what $this actually means. When used inside a class definition, $this is used to refer to an object of that class. So if you had a function foo inside AuthDB, and you needed to access $_db from within foo, you would use $this to tell PHP that you want the $_db from the same object that foo belongs to.

                  You might want to read this StackOverflow question: PHP: self vs $this

                  這篇關于致命錯誤:不在對象上下文中時使用 $this的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                2. <legend id='CUEf8'><style id='CUEf8'><dir id='CUEf8'><q id='CUEf8'></q></dir></style></legend>

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

                          <tbody id='CUEf8'></tbody>

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

                        • <bdo id='CUEf8'></bdo><ul id='CUEf8'></ul>

                            <tfoot id='CUEf8'></tfoot>
                            主站蜘蛛池模板: 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 鲁尔圆锥接头多功能测试仪-留置针测试仪-上海威夏环保科技有限公司 | 网络推广公司_网络营销方案策划_企业网络推广外包平台-上海澜推网络 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 合肥风管加工厂-安徽螺旋/不锈钢风管-通风管道加工厂家-安徽风之范 | 成都治疗尖锐湿疣比较好的医院-成都治疗尖锐湿疣那家医院好-成都西南皮肤病医院 | 万师讲师网-优质讲师培训师供应商,讲师认证,找讲师来万师 | 压力变送器-上海武锐自动化设备有限公司 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | 大连海岛旅游网>>大连旅游,大连海岛游,旅游景点攻略,海岛旅游官网 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂 | 振动传感器,检波器-威海广达勘探仪器有限公司 | 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 软启动器-上海能曼电气有限公司| 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 广西资质代办_建筑资质代办_南宁资质代办理_新办、增项、升级-正明集团 | 不锈钢闸阀_球阀_蝶阀_止回阀_调节阀_截止阀-可拉伐阀门(上海)有限公司 | 涂层测厚仪_漆膜仪_光学透过率仪_十大创新厂家-果欧电子科技公司 | 电子元器件呆滞料_元器件临期库存清仓尾料_尾料优选现货采购处理交易商城 | 武汉森源蓝天环境科技工程有限公司-为环境污染治理提供协同解决方案 | 蓝牙音频分析仪-多功能-四通道-八通道音频分析仪-东莞市奥普新音频技术有限公司 | 河南mpp电力管_mpp电力管生产厂家_mpp电力电缆保护管价格 - 河南晨翀实业 | 聚氨酯复合板保温板厂家_廊坊华宇创新科技有限公司 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 注塑模具_塑料模具_塑胶模具_范仕达【官网】_东莞模具设计与制造加工厂家 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | PU树脂_水性聚氨酯树脂_聚氨酯固化剂_聚氨酯树脂厂家_宝景化工 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 棉柔巾代加工_洗脸巾oem_一次性毛巾_浴巾生产厂家-杭州禾壹卫品科技有限公司 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 海德莱电力(HYDELEY)-无功补偿元器件生产厂家-二十年专业从事电力电容器 | DAIKIN电磁阀-意大利ATOS电磁阀-上海乾拓贸易有限公司 | 六维力传感器_六分量力传感器_模腔压力传感器-南京数智微传感科技有限公司 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 北京燃气公司 用户服务中心 | RTO换向阀_VOC高温阀门_加热炉切断阀_双偏心软密封蝶阀_煤气蝶阀_提升阀-湖北霍科德阀门有限公司 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 |