HyperDB icon indicating copy to clipboard operation
HyperDB copied to clipboard

fix: resolve warnings in php 8

Open heyjones opened this issue 3 years ago • 6 comments

Resolves the following warnings when upgrading to PHP 8:

  • compact(): Undefined variable $server in db.php on line 722
  • Undefined variable $server in db.php on line 726

heyjones avatar Jun 18 '22 14:06 heyjones

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

heyjones avatar Jun 18 '22 17:06 heyjones

@rinatkhaziev could you please take a look as well?

sjinks avatar Jun 19 '22 23:06 sjinks

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

rinatkhaziev avatar Jun 21 '22 16:06 rinatkhaziev

@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 avatar Jun 21 '22 16:06 heyjones

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

heyjones avatar Jun 22 '22 14:06 heyjones

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

sonarqubecloud[bot] avatar Feb 18 '23 05:02 sonarqubecloud[bot]