Make WordPress Core

Opened 22 months ago

Closed 22 months ago

Last modified 8 months ago

#56836 closed defect (bug) (duplicate)

PHP 8.1 Deprecation Warning for mysqli_real_connect

Reported by: nickchomey's profile nickchomey Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.0.2
Component: Database Keywords: php81
Focuses: Cc:

Description

I'm getting these deprecation warnings in the debug.log

[16-Oct-2022 23:14:52 UTC] PHP Deprecated:  mysqli_real_connect(): Passing null to parameter #5 ($database) of type ?string is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753
[16-Oct-2022 23:14:52 UTC] PHP Deprecated:  mysqli_real_connect(): Passing null to parameter #6 ($port) of type ?int is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753
[16-Oct-2022 23:14:52 UTC] PHP Deprecated:  mysqli_real_connect(): Passing null to parameter #7 ($socket) of type ?string is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753

I'm using PHP 8.1, so assume it is due to that. It probably happens in 8.0 as well.

If I trace the error with Xdebug, I can see that the problem is
a) null is simply hardcoded for param 5
b) port and socket are set to null if they aren't included in wp-config.php e.g. define('DB_HOST', "localhost");

If I manually change param 5 to "" and

$port    = "";
$socket  = "";

in wp-includes/wp-db.php -> parse_db_host()

then the problem goes away.

Change History (7)

#1 @nickchomey
22 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #54877.

Closing this as it is already an issue here https://core.trac.wordpress.org/ticket/54877#comment:42

Though, just one clarification - it should be $port = 0 since it is an int.

Last edited 22 months ago by nickchomey (previous) (diff)

#2 @SergeyBiryukov
22 months ago

  • Keywords php81 added

#3 @nickchomey
22 months ago

  • Keywords php81 removed

I've decided to close this as well as remove my comment from #54877 as it seems like there's a bug in Litespeed's lsphp81 that isn't treating mysqli_real_connect's parameters as nullable.

#4 @nickchomey
22 months ago

  • Focuses coding-standards removed
  • Keywords php81 added

#5 @SergeyBiryukov
22 months ago

Hi there, welcome back to WordPress Trac!

Just adding some context from #54877:

P.S. Ah, it looks like this is already noted above.

#6 @desrosj
22 months ago

  • Milestone Awaiting Review deleted

#7 @SergeyBiryukov
8 months ago

#60073 was marked as a duplicate.

Note: See TracTickets for help on using tickets.