Title: PHP 8.0.17 TypeError
Last modified: April 22, 2022

---

# PHP 8.0.17 TypeError

 *  Resolved [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/)
 * Hello,
    After switching to PHP 8.0.17 from PHP 7.4 we noticed some errors in 
   the log. One of them seems to be happening because of the query monitor plugin.
   When deactivating it – the error is no more. WP version: 5.9.3 Hosting: Cloudways,
   Debian
 *     ```
       php -v
       PHP 8.0.17 (cli) (built: Mar 20 2022 17:07:52) ( NTS )
       Copyright (c) The PHP Group
       Zend Engine v4.0.17, Copyright (c) Zend Technologies
           with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies
       ```
   
 *     ```
       TypeError: Uncaught exception 'TypeError' with message 'mysqli::real_connect(): Argument #5 ($port) must be of type ?int, string given' in /home/655799.cloudwaysapps.com/mqmfrzyxhx/public_html/wp-includes/wp-db.php:2162
       in mysqli::real_connect called at ? (?)
       in mysqli_query called at /home/<apppath>/public_html/wp-includes/wp-db.php (2162)
       in wpdb::_do_query called at /home/<apppath>/public_html/wp-includes/wp-db.php (2051)
       in wpdb::query called at /home/<apppath>/public_html/wp-includes/wp-db.php (2829)
       in wpdb::get_results called at /home/<apppath>/public_html/wp-includes/class-wp-user-query.php (776)
       in WP_User_Query::query called at /home/<apppath>/public_html/wp-includes/class-wp-user-query.php (78)
       in WP_User_Query::__construct called at /home/<apppath>/public_html/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php (64)
       in WP_Sitemaps_Users::get_url_list called at /home/<apppath>/public_html/wp-includes/sitemaps/class-wp-sitemaps.php (208)
       in WP_Sitemaps::render_sitemaps called at /home/<apppath>/public_html/wp-includes/class-wp-hook.php (307)
       in WP_Hook::apply_filters called at /home/<apppath>/public_html/wp-includes/class-wp-hook.php (331)
       in WP_Hook::do_action called at /home/<apppath>/public_html/wp-includes/plugin.php (474)
       in do_action called at /home/<apppath>/public_html/wp-includes/template-loader.php (13)
       in require_once called at /home/<apppath>/public_html/wp-blog-header.php (19)
       in require called at /home/<apppath>/public_html/index.php (17)
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [John Blackbourn](https://wordpress.org/support/users/johnbillion/)
 * (@johnbillion)
 * WordPress Core Developer
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15581432)
 * Thanks for the report.
 * As Query Monitor doesn’t appear anywhere in that stack trace can you definitely
   confirm that the error only happens when QM is active?
 * The port is parsed from the `DB_HOST` constant by `wpdb::parse_db_host()` and
   QM doesn’t make any changes to this. Happy to look into it further if you’re 
   sure that QM is causing this.
 *  Thread Starter [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15585303)
 * Indeed,
    I found out it happens on other occasions (as seen in previous trace).
   Here is one trace with the query-monitor in it (this one stopped happening after
   disabling the query monitor):
 * in mysqli::real_connect called at ? (?)
    in mysqli_query called at /home/<app_name
   >/public_html/wp-includes/wp-db.php (2162) in wpdb::_do_query called at /home/
   <app_name>/public_html/wp-includes/wp-db.php (2051) in wpdb::query called at /
   home/<app_name>/public_html/wp-content/plugins/query-monitor/wp-content/db.php(
   114) in QM_DB::query called at /home/<app_name>/public_html/wp-includes/wp-db.
   php (2829) in wpdb::get_results called at /home/<app_name>/public_html/wp-includes/
   class-wp-user-query.php (776) in WP_User_Query::query called at /home/<app_name
   >/public_html/wp-includes/class-wp-user-query.php (78) in WP_User_Query::__construct
   called at /home/<app_name>/public_html/wp-includes/sitemaps/providers/class-wp-
   sitemaps-users.php (118) in WP_Sitemaps_Users::get_max_num_pages called at /home/
   <app_name>/public_html/wp-includes/sitemaps/class-wp-sitemaps-provider.php (76)
   in WP_Sitemaps_Provider::get_sitemap_type_data called at /home/<app_name>/public_html/
   wp-includes/sitemaps/class-wp-sitemaps-provider.php (106) in WP_Sitemaps_Provider::
   get_sitemap_entries called at /home/<app_name>/public_html/wp-includes/sitemaps/
   class-wp-sitemaps-index.php (60) in WP_Sitemaps_Index::get_sitemap_list called
   at /home/<app_name>/public_html/wp-includes/sitemaps/class-wp-sitemaps.php (192)
   in WP_Sitemaps::render_sitemaps called at /home/<app_name>/public_html/wp-includes/
   class-wp-hook.php (307) in WP_Hook::apply_filters called at /home/<app_name>/
   public_html/wp-includes/class-wp-hook.php (331) in WP_Hook::do_action called 
   at /home/<app_name>/public_html/wp-includes/plugin.php (474) in do_action called
   at /home/<app_name>/public_html/wp-includes/template-loader.php (13) in require_once
   called at /home/<app_name>/public_html/wp-blog-header.php (19) in require called
   at /home/<app_name>/public_html/index.php (17)
 * Here is the definition of the DB_HOST (it has no port):
    define(‘DB_HOST’, ‘localhost’);
    -  This reply was modified 4 years, 1 month ago by [Anatolie](https://wordpress.org/support/users/toleanu/).
 *  Thread Starter [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15585813)
 * Can you/I edit the initial post ? I forgot to mask the path of the app in the
   first row of the error.
    I can’t seem to find a way.
 * Moreover : after more debugging it seems to be a bug in PHP 8.0 or WP. I took
   the code in a separate file and run it with php cli and can reproduce:
 *     ```
       <?php
       $dbh = mysqli_init();
       mysqli_real_connect( $dbh, 'localhost', '<dbuser>', '<pass>', '<dbname>', null , null);
       mysqli_query($dbh, "SELECT post_id FROM wp_postmeta WHERE meta_value = 'teststring'");
       ```
   
 * Running this sometimes works sometimes we get the error from above.
    If we remove
   the last `null` which should be the $socket arg, then it always works. Also if
   we specify the $port argument instead of `null`, also works.
 * `mysqli_real_connect( $dbh, 'localhost', '<dbuser>', '<pass>', '<dbname>', null);`
 *  Thread Starter [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15585910)
 * Another observation:
    It happens only with heavier queries e.g. `LIKE` on `post_content`
   or `=` and `LIKE` on `meta_value`. With simple queiries e.g. `meta_key = 'something'`
   and `post_title LIKE %somethingelse%` on simple columns, this does not happen(
   or the rate is so low I was not able to catch it).
    -  This reply was modified 4 years, 1 month ago by [Anatolie](https://wordpress.org/support/users/toleanu/).
    -  This reply was modified 4 years, 1 month ago by [Anatolie](https://wordpress.org/support/users/toleanu/).
    -  This reply was modified 4 years, 1 month ago by [Anatolie](https://wordpress.org/support/users/toleanu/).
 *  Thread Starter [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15586072)
 * So, for other with same error and with WP, without editing the WP core files,
   you can fix it by specifying the port in wp-config, for example :
 * `define('DB_HOST', '127.0.0.1:3306');`
 * change the host and port according to your DB server configuration.
    -  This reply was modified 4 years, 1 month ago by [Anatolie](https://wordpress.org/support/users/toleanu/).
 *  Plugin Author [John Blackbourn](https://wordpress.org/support/users/johnbillion/)
 * (@johnbillion)
 * WordPress Core Developer
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15586135)
 * Very strange, I can’t immediately see the cause but this indeed isn’t specific
   to Query Monitor or WordPress. Might be worth researching to see if this is a
   known bug in PHP.
 *  Thread Starter [Anatolie](https://wordpress.org/support/users/toleanu/)
 * (@toleanu)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15586284)
 * Can you/I edit the initial post ? I forgot to mask the path of the app in the
   first row of the error.
    I can’t seem to find a way.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘PHP 8.0.17 TypeError’ is closed to new replies.

 * ![](https://ps.w.org/query-monitor/assets/icon.svg?rev=2994095)
 * [Query Monitor](https://wordpress.org/plugins/query-monitor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/query-monitor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/query-monitor/)
 * [Active Topics](https://wordpress.org/support/plugin/query-monitor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/query-monitor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/query-monitor/reviews/)

## Tags

 * [typeerror](https://wordpress.org/support/topic-tag/typeerror/)

 * 7 replies
 * 2 participants
 * Last reply from: [Anatolie](https://wordpress.org/support/users/toleanu/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-17-typeerror/#post-15586284)
 * Status: resolved