Bugfix Issue 519 TestprojectOptions EWarning Fix - sebiboga/testlink-upgraded GitHub Wiki
Bugfix: Issue #519 — E_WARNING Undefined array key "testprojectOptions"
Problem
PHP 8 generates E_WARNING "Undefined array key 'testprojectOptions'" in printDocOptions.php:156 and resultsNavigator.php:100, with approximately 12 warnings across both files.
Root Cause
$_SESSION['testprojectOptions'] was a legacy session cache key that was never populated anywhere in the codebase. All 7 access sites across 6 files consumed this missing key:
lib/results/printDocOptions.php:156-158lib/results/resultsNavigator.php:100-102lib/functions/common.php:353-354lib/general/mainPage.php:187-189lib/general/asideMenu.php:50-51lib/testcases/tcEdit.php:407-410lib/testcases/tcAssignedToUser.php:331
Commit f4456736b added isset() guards to suppress the PHP 8 warnings, but the functional impact persisted: requirements-related features were silently disabled because the session read always returned false/null.
Fix
Replace all $_SESSION['testprojectOptions'] reads with live testproject::getOptions() DB queries, following the pattern already established in mainPage.php:539-540:
$tprojMgr = new testproject($db);
$tprojOpts = $tprojMgr->getOptions($tproject_id);
$requirementsEnabled = (!empty($tprojOpts) && isset($tprojOpts->requirementsEnabled))
? $tprojOpts->requirementsEnabled : false;
Files Changed
| File | Change |
|---|---|
lib/results/printDocOptions.php |
$tprojMgr->getOptions($args->tproject_id) via $dbHandler param |
lib/results/resultsNavigator.php |
Moved DB query to main scope (init_args has no $db) |
lib/functions/common.php |
$tprojMgr->getOptions($_SESSION['testprojectID']) in initTopMenu(&$db) |
lib/general/mainPage.php |
$tprojMgr->getOptions(intval($_SESSION['testprojectID'])) |
lib/general/asideMenu.php |
$tproject_mgr->getOptions($tprojectID) (reuse existing manager) |
lib/testcases/tcEdit.php |
$tprojOptMgr->getOptions($args->tproject_id) via $tcaseMgr->db |
lib/testcases/tcAssignedToUser.php |
Reuse $args->testprojectOptions from get_by_id() |
Verification
- All 7 files pass
php -lsyntax check - Browser test: zero new PHP warnings on resultsNavigator.php, mainPage.php, asideMenu.php
- Event Viewer: no new
testprojectOptionswarnings - Aside menu now correctly shows "Requirements Design" section when requirements are enabled