Zabs
Zabs

Reputation: 14142

Catchable Fatal Error: Object of class stdClass could not be converted to string in error on live site only

I have a test (localhost) website and a live site that use the same PHP code. I am getting the following error ONLY on my live site (doesn't happen on the localhost version using the same codebase.

Catchable Fatal Error: Object of class stdClass could not be converted to string in .... on line 486.

Note - line 486 is this line within the foreach loop - any ideas why it isn't working on live but ok for localhost?

$out .= sprintf("<tr><td>%s</td><td>%s</td></tr>", $error['title'], $error['description']);

Code Block

public function getErrorTable()
{
    $support_email_link = "<a href='" . $this->support_email . "'>" . $this->support_email . "</a>";

    $out = '<div style="width:100%;min-height:380px;text-align:center;"><p style="font-size: 30px;">Error encountered <i class="fa fa-times" style="color:#CC0000;"></i></p><span>Please contact ' . $support_email_link . "</span><br><table id='error_table'><thead><th>Error Title</th><th>Description</th></thead><tbody>";

    foreach ($this->errors as $error) {
        $out .= sprintf("<tr><td>%s</td><td>%s</td></tr>", $error['title'], $error['description']);
    }

    $out .= "</tbody></table></div>";

    return $out;
}

Upvotes: 1

Views: 1654

Answers (1)

j11e
j11e

Reputation: 381

I don't know what $this->errors is containing when getErrorTable is called, but the error message indicates that either $error['title'] or $error['description'] is an object, rather than a string.

Now, this can be caused by many things, from different PHP configuration to a different execution flow on your website. This is hard to tell from just this snippet. The easiest way for you to debug this issue is to simply print_r($error) in your foreach, or error_log(print_r($error, true)) if the website is in production and you don't want to just dump information to your visitors (which is probably a bad idea!).

Upvotes: 1

Related Questions