Support » Fixing WordPress » Catchable fatal error in formatting.php

  • Resolved joand

    (@joand)


    I am trying to help a client with his blog. When someone submits a comment, the following error occurs:

    Catchable fatal error: Object of class WP_Error could not be converted to string in …/wp-includes/formatting.php on line 959 The following is line 958 and 959 of formatting.php

    function wp_check_invalid_utf8( $string, $strip = false ) {
    	$string = (string) $string;

    I tried switching to the 2015 theme and disabling all plugins and the problem still persists.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi Joan,

    It’s a weird function to me because:

    1) $string is forbidden as php class, because it’s a system function, call it $string33 or $stringsomething, but NEVER $string, it’s a variable from php core – so you can’t name a function as $string like that – or fatal error

    So, solution, change the name of this $stringy function, example:

    $stringtest

    should be ok.

    Also, if you need to use/change text strings in php, I suggest something like this, there are tons of specific tools to manipulate text in php (please check http://php.net/manual/en/book.strings.php).

    Example:

    $stringtest = "abcezsr./sdqfkj'ww.comdsklfjhndsf";
    $myphpfunction = stripslashes (($stringtest));
    $myphpstring = $myphpfunction;
    $myphpfunctioncount = str_word_count (($myphpstring));
    echo "$myphpfunctioncount";

    Have a nice day,

    Hi Digico, thank you for taking the time to reply. This function is in a core WP file (wp-includes/formatting.php) Would I have to change it there? I am not so keen to change WP core files. Your reply that was sent to me by email is different than that above and it says “it will check all comments, but also everything on blog – no matter it crashes the site.” That makes me think that maybe it is something in the content of the site that is making it crash. Otherwise, since this is a core file, why isn’t this happening to everyone’s blog?

    I don’t know if this could have anything to do with it – but I noticed that some posts say they have comments (e.g. 4 comments, 11 comments) but when you click on that it takes you to the comment form, doesn’t show any comments. And there are absolutely no comments showing in the comment section of the dashboard.

    I tried to run a repair on the database with the WordPress repair script and it says that the Comments table is crashed and could not be repaired. I am waiting to get his control panel login to see if I can get in through phpMyAdmin (it is hosted with GoDaddy, hopefully they have phpMyAdmin)

    Hi. What Digico is saying makes absolutely zero sense to me and has nothing to do with the problem you are having.

    You are right in thinking that making changes to the WordPress core code base is always a bad idea. Don’t do that. Instead search for the problem elsewhere. It might be one of your plugins or your active theme behind this so the first step would be to deactivate them all for a little while. Your theme is the most likely culprit so focus on that first of all.

    Hi WP Gurus, thank you for your help. I did try switching to the default theme and deactivating all plugins before posting the problem here, and the problem persisted. I noticed that there were no comments showing in the admin section although some posts showed a comment count. So I used the database repair script which told me that the Comments table was crashed and could not be repaired. It must have actually repaired though as the comments are back in the admin section and comments can successfully be posted. So the problem, in case this helps anyone else, was a crashed Comments table in the database.

    Hi, I never said to change core, neither wp.

    Just said, using same name as “string” core PHP functions (not WP, PHP server) leads to fatal error. Which occured by the way.

    Nice if all is solved now, Joan.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Catchable fatal error in formatting.php’ is closed to new replies.