[乐意黎原创]php 抛Fatal error: Cannot use object of type stdClass as array in XXX的解决方法


php 使用 var_dump( $curDayItemsJson["comm_msg_info"]);


抛Fatal error:  Cannot use object of type stdClass as array in 错误,如图: 


items: 10

<b>Fatal error</b>:  Cannot use object of type stdClass as array in <b>E:\PHPCMS\Cms\www.aerchi.com\weixin\weixin-search.php</b> on line <b>490</b>



其实,数组中是返回的是一个对象,不能直接用[]来显示,正确的输出方法是: $curDayItemsJson->comm_msg_info

终于成功解决,标记一下。

乐意黎原创
本文地址:   http://blog.csdn.net/aerchi/article/details/51272067


发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

PHP:匹配哈希密码,用户输入不起作用[重复]

06-24

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/16525413/fatal-error-cannot-use-object-of-type-mysqli-result" dir="ltr">Fatal error: Cannot use object of type mysqli_result [closed]</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul> </div> <p>I am new to PHP and am trying to check whether a password provided by a user (login page) matches a hashed password stored in the db. The password in the db was hashed through <code>$pw = password_hash($_POST["pw"], PASSWORD_BCRYPT);</code> (the same approach I use for the user's input) and is stored in a <code>VARCHAR(255)</code> column. </p> <p>I now tried using password_verify to compare this with the user input but am getting the below error which is caused by the <code>else</code> part. </p> <p>Can someone tell me what I am doing wrong here ? I tried removing "<code>== true</code>" as well but that didn't work either. </p> <p><strong>My PHP:</strong></p> <pre><code>$email = $_POST["email"]; $pw = password_hash($_POST["pw"], PASSWORD_BCRYPT); $stmt = $conn->prepare("SELECT email, pw FROM Users WHERE email = ?"); $stmt->bind_param('s', $email); $stmt->execute(); $result = $stmt->get_result(); if(mysqli_num_rows($result) == 0){ echo "Email has not been registered yet"; }else{ if(password_verify($pw, $result["pw"]) == true){ echo "Password correct"; }else{ echo "Password incorrect"; } }; </code></pre> <p><strong>The error:</strong> </p> <pre><code>"Fatal error: Cannot use object of type mysqli_result as array..." </code></pre> <p><strong>Update:</strong><br> To me this is different to the other question referred to as possible duplicate as in my case I either get the above error or (when following Bing's approach below) the result is always "Password incorrect" - independent of the input. </p> <p>Many thanks in advance. </p> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览