• Resolved matsubobo

    (@matsubobo)


    I’m running 10 WordPress sites and I’ve got following error on a few sites of them.

    
    `[08-Oct-2021 02:37:19 UTC] PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, string given in /home/matsu/Sites/teraren.com/diary/wp-content/plugins/google-sitemap-generator/sitemap-builder.php:475
    Stack trace:
    #0 /home/matsu/Sites/teraren.com/diary/wp-includes/class-wp-hook.php(303): GoogleSitemapGeneratorStandardBuilder->Index(Object(GoogleSitemapGenerator))
    #1 /home/matsu/Sites/teraren.com/diary/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
    #2 /home/matsu/Sites/teraren.com/diary/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #3 /home/matsu/Sites/teraren.com/diary/wp-content/plugins/google-sitemap-generator/sitemap-core.php(1623): do_action('sm_build_index', Object(GoogleSitemapGenerator))
    #4 /home/matsu/Sites/teraren.com/diary/wp-content/plugins/google-sitemap-generator/sitemap-loader.php(327): GoogleSitemapGenerator->ShowSitemap(Array)
    #5 /home/matsu/Sites/teraren.com/diary/wp-content/plugins/google-sitemap-generator/sitemap-loader.php(202): GoogleSitemapGeneratorLoader::CallShowSitemap('params=')
    #6 /home/matsu/Sites/teraren.com/diary/wp-includes/class-wp-hook.php(301): GoogleSitemapGeneratorLoader::DoTemplateRedirect()
    #7 /home/matsu/Sites/teraren.com/diary/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(true, Array)
    #8 /home/matsu/Sites/teraren.com/diary/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #9 /home/matsu/Sites/teraren.com/diary/wp-includes/template-loader.php(13): do_action('template_redire...')
    #10 /home/matsu/Sites/teraren.com/diary/wp-blog-header.php(19): require_once('/home/matsu/Sit...')
    #11 /home/matsu/Sites/teraren.com/diary/index.php(17): require('/home/matsu/Sit...')
    #12 {main}
      thrown in /home/matsu/Sites/teraren.com/diary/wp-content/plugins/google-sitemap-generator/sitemap-builder.php on line 475
    

    I wrote a patch to avoid the error.

    
    % diff -u /path/to/old/sitemap-builder.php /path/to/new/sitemap-builder.php
    --- /home/matsu/Sites/teraren.com/je1wfv/wp-content/plugins/google-sitemap-generator/sitemap-builder.php	2021-10-08 02:38:49.268861006 +0000
    +++ /home/matsu/Sites/teraren.com/matsu/blog/wp-content/plugins/google-sitemap-generator/sitemap-builder.php	2021-09-03 09:01:22.833828604 +0000
    @@ -472,7 +472,7 @@
     		}
    
     		$pages = $gsg->GetPages();
    -		if(count($pages) > 0) {
    +		if(is_array($pages) && count($pages) > 0) {
     			foreach($pages AS $page) {
     				if($page instanceof GoogleSitemapGeneratorPage && $page->GetUrl()) {
     					$gsg->AddSitemap("externals", null, $blogUpdate);
    

    Root cause is that the original code expects $pages is an array but the content of the variable is string.

    My server environment.

    
    $ php -v
    PHP 8.0.8 (cli) (built: Jul  7 2021 17:35:32) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v4.0.8, Copyright (c) Zend Technologies
        with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies
    

    Wordpress 5.8.1

    I’d appriciate if the patch is merged.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[NSFW] Got an error “PHP Fatal error: Uncaught TypeError: count()”’ is closed to new replies.