Automattic / Automattic/HyperDB

Undefined variable: host

Open
#40 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
150
Forks
28
PR merge metrics
No merged PRs in 30d

Description

In `db_connect()`, if the condition `while ( ( $group_key = array_shift( $this->unused_servers[ $dbhname ] ) ) ) {` is never met, `$host` and `$port` will be undefined when the `$error_details` array is created, generating a PHP notice.

It could be fixed by just adding:

```
if ( ! isset( $host ) ) { $host = ''; }
if ( ! isset( $port ) ) { $port = ''; }
```

before `$error_details`, but I don't know if that would be masking the root issue (should the `while` loop always execute at least once?) or not.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in db_connect() and reproduce the path where the while condition never succeeds. Inspect how $error_details uses $host and $port, then determine whether the loop should execute or whether unset values need handling; done means the notice is resolved without masking the underlying connection behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.