Skip to content

Conversation

@dsaha1656
Copy link

Fix: Ensure $db read/write keys are defined in add_database

The HyperDB::add_database function was potentially exiting with undefined '$read' and '$write' variables if they were not passed in the initial configuration array.

This occurs because:

  1. The function uses an 'extract' call (line ~519 in the calling context) which may not define '$read' or '$write'.
  2. The logic to set $read/$write defaults only runs if the variable is not set (e.g., if ( ! isset( $read ) ) { $read = 1; }).
  3. If the variable is not defined at all (as opposed to being defined but null or false), the isset() check passes, but the following code might still use the undefined variable, leading to a PHP 'Undefined Variable' notice/error.

This change corrects the logic by ensuring that the $db array (which represents the database configuration being added) explicitly contains the 'read' and 'write' keys, defaulting them to 1 if they are not present in the configuration passed to the function.

This resolves potential runtime errors when calling add_database with minimal configuration options.

Fix: Ensure $db read/write keys are defined in add_database

The HyperDB::add_database function was potentially exiting with undefined
'$read' and '$write' variables if they were not passed in the initial
configuration array.

This occurs because:
1. The function uses an 'extract' call (line ~519 in the calling context)
   which may not define '$read' or '$write'.
2. The logic to set $read/$write defaults only runs *if* the variable
   is not set (e.g., `if ( ! isset( $read ) ) { $read = 1; }`).
3. If the variable is *not* defined at all (as opposed to being defined
   but null or false), the `isset()` check passes, but the following code
   might still use the undefined variable, leading to a PHP 'Undefined
   Variable' notice/error.

This change corrects the logic by ensuring that the `$db` array
(which represents the database configuration being added) explicitly
contains the `'read'` and `'write'` keys, defaulting them to `1`
if they are not present in the configuration passed to the function.

This resolves potential runtime errors when calling `add_database`
with minimal configuration options.
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant