From d9a54eefa9e264e2c1c6552e3ce4a451c127bfee Mon Sep 17 00:00:00 2001 From: Dibyendu Saha Date: Fri, 21 Nov 2025 17:20:20 +0530 Subject: [PATCH] Fix: Ensure $db read/write keys are defined in add_database 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. --- db.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db.php b/db.php index 6643331..3e2dafc 100644 --- a/db.php +++ b/db.php @@ -264,10 +264,12 @@ public function add_database( $db ) { if ( ! isset( $read ) ) { $read = 1; + $db['read'] = 1; } if ( ! isset( $write ) ) { $write = 1; + $db['write'] = 1; } unset( $db['dataset'] );