PDO错误无法将stdClass类型的对象用作数组


PDO error Cannot use object of type stdClass as array

在使用PHP时,我一直在尝试学习PDO而不是MySQL,我有一些代码看不出错误在哪里:

<?php
include('includes/db_connection.php');
include('includes/sessions.php');
include('includes/functions.php');
include('includes/header.php');
include('includes/loginnav.php');
$row = DB::getInstance()->selectOneByField('membership', 'username', $member);
$logged_in_users_id = $row['id'];
$result3 = DB::getInstance()->select('
    SELECT  *
    FROM    `pms`
    WHERE   `sender_id` = :logged_in_users_id
    ORDER   BY `date_added` DESC',
[
    'logged_in_users_id' => $logged_in_users_id
]);
if (count($result3) == 0) {
    stderr('No messages have been sent. (<a href="inbox.php">Inbox</a>)');
}
?>
<div class="panel panel-primary">
    <div class="panel-heading">Sentbox</div>
    <div class="panel-body">
        <table class="table table-striped table-condensed table-responsive table-hover">
            <thead>
                <tr>
                    <th>Subject</td>
                    <th>Date Sent</td>
                    <th>To User</td>
                    <th>Read (<font color="green">Y</font>&nbsp;/&nbsp;<font color="red">N</font>)</td>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($result3 as $row) { ?>
                    <?php
                        $id = $row['id'];
                        $sendee_id = $row['reciever_id'];
                        $read = $row['read_flag'];
                        $row = DB::getInstance()->selectOneByField('membership', 'id', $sendee_id);
                        $sendee = $row['username'];
                        $sendee_id = $row['id'];
                        $row_2 = DB::getInstance()->selectOneByField('pms', 'reciever_id', $logged_in_users_id, PDO::FETCH_OBJ);
                    ?>
                    <tr>
                        <td><strong><?php echo htmlspecialchars($row_2['subject']) ?></strong></td>
                        <td><?php echo htmlspecialchars($row_2['date_added']) ?></td>
                        <td><a href="user-details.php?id=<?php echo $sendee_id ?>"><?php echo htmlspecialchars($sendee) ?></td>
                        <td style="color: <?php echo ($read == 'Y')? 'green': 'red' ?>"><strong><?php echo htmlspecialchars($read) ?></strong></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</div>

第52行出现错误:"PHP致命错误:无法将stdClass类型的对象用作中的数组",该行开始于以下行:

<td><strong><?php echo htmlspecialchars($row_2['subject']) ?></strong></td>

我试着调试错误是什么,但我现在被卡住了,任何帮助都将不胜感激。

尝试$row_2->subject而不是$row_2['subject']

访问StdClass对象时,请使用->。