Issue upgrading WordPress Site to PHP 8 due to Plugin – Cannot access offset of type string on string

I tried to upgrade a WordPress Site however I got the dreaded

There Has Been a Critical Error on Your Website

I turned full Debug mode on the website wp_config.php to show me the error

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

Uncaught TypeError: Cannot access offset of type string on string

Looking at the code the plugin’s vendor declared a String for an Array variable

                $post_services_name = "";

                foreach ( $pt_posts_services as $post ) : setup_postdata( $post );
                    $post_services_name[$post->post_title]=$post->post_name;

                endforeach;

Defining the array before fixed it

                    $post_services_name = array();

                    foreach ( $pt_posts_services as $post ) : setup_postdata( $post );
                        $post_services_name[$post->post_title]=$post->post_name;

                    endforeach;
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...