[wp-trac] [WordPress Trac] #54877: Occasional PHP exception being thrown on WPDB/MySQLi connections

WordPress Trac noreply at wordpress.org
Thu Apr 7 22:15:54 UTC 2022


#54877: Occasional PHP exception being thrown on WPDB/MySQLi connections
-----------------------------------+---------------------
 Reporter:  johnjamesjacoby        |       Owner:  (none)
     Type:  enhancement            |      Status:  new
 Priority:  normal                 |   Milestone:  6.0
Component:  Database               |     Version:  1.5
 Severity:  normal                 |  Resolution:
 Keywords:  2nd-opinion has-patch  |     Focuses:
-----------------------------------+---------------------

Comment (by jrf):

 Saw mention of this ticket in Slack and thought I'd have a quick look.

 If I look at the patch + look at the usage of the `$port` variable in
 various places in the `wp-db.php` file, I'm seeing potential problems.

 The `$port` parameter in the `mysqli::real_connect()` function is
 ''optional'', but by the looks of it, it is not ''nullable''.
 See: https://www.php.net/manual/en/mysqli.real-connect.php

 As of PHP 8.1, passing `null` (the default value for `$port` in various
 places) to a non-nullable parameter will result in a deprecation notice
 and this will become a fatal error in PHP 9.0.

 As the potential use of `null` in these calls was not yet found so far via
 the test suite, this indicates to me there is also a shortage of tests
 covering this class.

 In other words, I would recommend the following actions:
 1. Do a full review of the parameters passed to
 `mysqli::real_connect()`/`mysqli_real_connect()` function calls throughout
 the `wp-db.php` file to ensure parameter defaults passed will not cause
 PHP 8.1 deprecation notices.
 2. Add dedicated tests to cover those situations with the risks of the
 deprecation notice to prevent regressions for any patches put in place.
 This includes adding tests to cover the currently proposed patch.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54877#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list