Linux, 工作, 生活, 家人

Software

WordPress Fatal error: Uncaught TypeError: count()

Shorter message:

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in formatting.php

Conclusion

Root cause is WordPress uses the regular expression to convert content text smilies to images. It will exhaust the php pcre library backtrack quickly. Especially when the images in the the article over 500.

Just keep the images number under 500 or separate  it into several articles.

if unfortunately, it happend, add “pcre.backtrack_limit=1000000000” to php.ini and restart website, it might make it work again, would be very very very slow to load the page.

If still cannot solve this problem, or too slow, probably use the number “pcre.backtrack_limit=10000000” can make it work. because default value is not so big like, when it can edit the article again, just remove some images can make it work.

How to Get the debug message?

Enable the debug in the wp-config.php, turn on following messages in the file.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );

Or check the web server error log.
Original Message

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in formatting.php

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in /var/www/htdocs/wp-includes/formatting.php:3507\nStack trace:\n#0 /var/www/htdocs/wp-includes/class-wp-hook.php(324): convert_smilies()\n#1 /var/www/htdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters()\n#2 /var/www/htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/links/class-links.php(171): apply_filters()\n#3 /var/www/htdocs/wp-content/plugins/seo-by-rank-math/includes/modules/links/class-links.php(59): RankMath\\Links\\Links->process()\n#4 /var/www/htdocs/wp-includes/class-wp-hook.php(326): RankMath\\Links\\Links->save_post()\n#5 /var/www/htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#6 /var/www/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action()\n#7 /var/www/htdocs/wp-includes/post.php(4828): do_action()\n#8 /var/www/htdocs/wp-includes/post.php(4930): wp_insert_post()\n#9 /var/www/htdocs/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(880): wp_update_post()\n#10 /var/www/htdocs/wp-includes/rest-api/class-wp-rest-server.php(1230): WP_REST_Posts_Controller->update_item()\n#11 /var/www/htdocs/wp-includes/rest-api/class-wp-rest-server.php(1063): WP_REST_Server->respond_to_request()\n#12 /var/www/htdocs/wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch()\n#13 /var/www/htdocs/wp-includes/rest-api.php(428): WP_REST_Server->serve_request()\n#14 /var/www/htdocs/wp-includes/class-wp-hook.php(324): rest_api_loaded()\n#15 /var/www/htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#16 /var/www/htdocs/wp-includes/plugin.php(565): WP_Hook->do_action()\n#17 /var/www/htdocs/wp-includes/class-wp.php(418): do_action_ref_array()\n#18 /var/www/htdocs/wp-includes/class-wp.php(813): WP->parse_request()\n#19 /var/www/htdocs/wp-includes/functions.php(1336): WP->main()\n#20 /var/www/htdocs/wp-blog-header.php(16): wp()\n#21 /var/www/htdocs/index.php(17): require('...')\n#22 {main}\n  thrown in /var/www/htdocs/wp-includes/formatting.php

ref.
Fatal error: Uncaught TypeError: count():

發佈留言