• Running WordPress 3.8 and PHP 5.4.20

    So I’m getting this notice in my php error log basically every 15 seconds – PHP Notice: Array to string conversion in /home/websaum/public_html/wp-includes/formatting.php on line 2809
    which is from this function –

    function _deep_replace( $search, $subject ) {
    	$subject = (string) $subject;
    
    	$count = 1;
    	while ( $count ) {
    		$subject = str_replace( $search, '', $subject, $count );
    	}
    
    	return $subject;
    }

    The file hasn’t been corrupted or modified.

Viewing 2 replies - 1 through 2 (of 2 total)
  • From that it looks like whatever is being passed in for $search is an array, and not a string as the function expects.

    As for how to track that down, that’s probably a bit harder. I’d start off by doing the standard de-bigging process of deactivating all plugins and switching to the default theme. Then one-by-one re-enable each plugin and then the theme, and test in between each one to see if the problem still exists. That should tell you whcih plugin or your theme that’s causing the problem.

    This seems to be a ‘standard’ issue in many WP installations – I also stumbled across it while trying to debug another issue: with debug output activated the error occurs many times. (running WPv3.9.1)

    Two locations highlighted for me (in wp_includes/formatting.php):
    line #448: function _wp_specialchars
    line #583: function wp_check_invalid_utf8
    … but could easily arise in several other instances.

    To correct this, code needs to check for arrays being passed, and either reject them, or process them. I chose the latter, adding the following code to each immediately after the function declaration:
    for _wp_specialchars:

    if( is_array($string) ){
    		foreach($string as $k=>$sVal){
    			$string[$k] = _wp_specialchars( $sVal, $quote_style, $charset, $double_encode );
    		}
    		return $string;
    	}

    for wp_check_invalid_utf8:

    if( is_array($string) ){
    		foreach($string as $k=>$sVal){
    			$string[$k] = wp_check_invalid_utf8( $sVal, $strip );
    		}
    		return $string;
    	}

    Don’t know if this is really fixing anything – but site appears to be working, and without these notices occurring.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Notice: Array to String Conversion in formatting.php’ is closed to new replies.