Automattic / HyperDB

HyperDB is an advanced database class that supports replication, failover, load balancing, and partitioning.
105 stars 22 forks source link

fix: resolve warnings in php 8 #56

Open heyjones opened 2 years ago

heyjones commented 2 years ago

Resolves the following warnings when upgrading to PHP 8:

heyjones commented 2 years ago

I’m assuming there’s a better default for this than null but I’m not that familiar with the rest of the code.

sjinks commented 2 years ago

@rinatkhaziev could you please take a look as well?

rinatkhaziev commented 2 years ago

@heyjones could you please provide steps to reproduce the issue? I'm not able to trigger the behavior you describe on a regular request.

heyjones commented 2 years ago

@rinatkhaziev here are the constants in my wp-config.php:

define( 'DB_NAME', 'local' );
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', 'root' );
define( 'DB_HOST', 'localhost' );

define( 'RO_NAME', 'local' );
define( 'RO_USER', 'root' );
define( 'RO_PASSWORD', 'root' );
define( 'RO_HOST', 'localhost' );

define( 'WP_ENVIRONMENT_TYPE', 'development' );

They match locally since I only have one db, but in prod they vary. I see this error in wp-admin:

Warning: compact(): Undefined variable $server in /Users/jones/Sites/collectivist.local/app/public/wp-content/db.php on line 722

When applying the code in this PR, the warning is removed. I'm open to suggestions for a better solution, or since I don't have WP_DEBUG set in prod I assume I won't even see these PHP warnings but figured I'd submit this anyways. Thanks!

heyjones commented 2 years ago

When I tail my logs locally, I do see several instances of this error:

WordPress database error 2022-06-22 14:47:11 Can't select global__r - 
'referrer' => 'wp.local/',
'server' => ,
'host' => localhost,
'error' => ,
'errno' => 0,
'server_state' => down [ > 0.2 ] (61) 'Connection refused'
'lagged_status' => 3 for query 
            SELECT  wp_blogs.blog_id
            FROM wp_blogs 
            WHERE domain = 'wp.local' AND path = '/'
            ORDER BY wp_blogs.blog_id ASC
            LIMIT 1
         made by WP_Site_Query::get_site_ids
sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication