Warning with PHP upgrade to 7.3

Warning: count(): Parameter must be an array or an object that implements Countable in …/wp-includes/post-template.php on line 310?

The following patch in the “post-template.php” was successful.

/*    if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
         $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
     }
 */ //replaced by the following 2019/11/11 k.n.
 if ( ! empty( $pages ) ) {
     if ( $page > count( $pages ) ) // if the requested page doesn't exist
         $page = count( $pages ); // give them the highest numbered page that DOES exist} else {
    $page = 0;
}
//replace end