Skip to content

fix(installer): guard optional function calls that fatal on PHP 8.2#60

Merged
mambax7 merged 2 commits into
XOOPS:masterfrom
mambax7:fix/installer-protector-undefined-function-guards
May 15, 2026
Merged

fix(installer): guard optional function calls that fatal on PHP 8.2#60
mambax7 merged 2 commits into
XOOPS:masterfrom
mambax7:fix/installer-protector-undefined-function-guards

Conversation

@mambax7
Copy link
Copy Markdown
Contributor

@mambax7 mambax7 commented May 15, 2026

Two unrelated installer-time crashes share the same root cause: PHP's @ operator does not suppress 'undefined function' fatal errors, and XOOPS's custom error handler ignores @ for warnings, so both spots logged or fataled on environments where the called function or backing file was absent.

  • install/page_modcheck.php: @mysqli_get_client_info() crashed the requirements page when the mysqli extension was not loaded, hiding the very diagnostic meant to surface that condition. Guard with function_exists() and pass an empty info string when missing; xoDiag() still reports MySQLi as missing via the existing function_exists('mysqli_connect') flag.

  • xoops_lib/modules/protector/class/protector.php: the constructor read its configcache via @file_get_contents() before the cache was ever written. On a fresh install the cache file does not exist until postcheck_functions.php calls updateConfFromDb(), and every page in between logged a warning to log.txt because XoopsLogger's error handler does not honour @. Guard with is_file() and treat a missing cache as an empty serialized payload; subsequent unserialize/empty checks already handle that shape.

Reported against PHP 8.2.31 / MySQL 5.7.44 / Apache 2.4.66 on Windows during 2.7.0 install testing.

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of installer requirements detection.
    • Enhanced stability of system configuration loading.

Review Change Stack

Two unrelated installer-time crashes share the same root cause:
PHP's @ operator does not suppress 'undefined function' fatal errors,
and XOOPS's custom error handler ignores @ for warnings, so both
spots logged or fataled on environments where the called function
or backing file was absent.

- install/page_modcheck.php: @mysqli_get_client_info() crashed the
  requirements page when the mysqli extension was not loaded, hiding
  the very diagnostic meant to surface that condition. Guard with
  function_exists() and pass an empty info string when missing;
  xoDiag() still reports MySQLi as missing via the existing
  function_exists('mysqli_connect') flag.

- xoops_lib/modules/protector/class/protector.php: the constructor
  read its configcache via @file_get_contents() before the cache
  was ever written. On a fresh install the cache file does not
  exist until postcheck_functions.php calls updateConfFromDb(),
  and every page in between logged a warning to log.txt because
  XoopsLogger's error handler does not honour @. Guard with
  is_file() and treat a missing cache as an empty serialized
  payload; subsequent unserialize/empty checks already handle that
  shape.

Reported against PHP 8.2.31 / MySQL 5.7.44 / Apache 2.4.66 on
Windows during 2.7.0 install testing.
Copilot AI review requested due to automatic review settings May 15, 2026 08:08
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@mambax7 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 51 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1212e133-e929-4e7c-b047-3e5bf5102771

📥 Commits

Reviewing files that changed from the base of the PR and between 37136ae and 47a02ae.

📒 Files selected for processing (1)
  • htdocs/install/page_modcheck.php

Walkthrough

This pull request replaces error suppression operators (@) in two separate initialization paths with explicit conditional checks. The installer's MySQLi client info now verifies function existence before calling it, and the protector's config cache now checks file existence before reading the cache file.

Changes

Error Suppression Removal

Layer / File(s) Summary
Installer MySQLi client info display
htdocs/install/page_modcheck.php
MySQLi client information reporting now calls mysqli_get_client_info() only if the function exists, falling back to an empty string, replacing unconditional @mysqli_get_client_info() error suppression.
Protector config-cache file loading
htdocs/xoops_lib/modules/protector/class/protector.php
Config cache initialization stores the cache file path in a variable, checks existence with is_file() before reading, and defaults _conf_serialized to an empty string on missing files instead of using suppressed @file_get_contents().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: guarding optional function calls to prevent fatal errors on PHP 8.2, which aligns with both file modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.12%. Comparing base (b563cbc) to head (47a02ae).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
htdocs/install/page_modcheck.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #60      +/-   ##
============================================
+ Coverage     18.04%   18.12%   +0.08%     
- Complexity     7845     7854       +9     
============================================
  Files           665      666       +1     
  Lines         43083    43136      +53     
============================================
+ Hits           7775     7820      +45     
- Misses        35308    35316       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@htdocs/install/page_modcheck.php`:
- Line 62: Remove the redundant error-suppression operator before
mysqli_get_client_info in the xoDiag call: since
function_exists('mysqli_get_client_info') already ensures the function exists,
delete the leading @ from `@mysqli_get_client_info`() so the line calls
mysqli_get_client_info() directly while keeping the existing guard and xoDiag
invocation intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6216c085-264d-4940-8ec5-f2c4968e5af0

📥 Commits

Reviewing files that changed from the base of the PR and between 37654dc and 37136ae.

📒 Files selected for processing (2)
  • htdocs/install/page_modcheck.php
  • htdocs/xoops_lib/modules/protector/class/protector.php

Comment thread htdocs/install/page_modcheck.php Outdated
The function_exists('mysqli_get_client_info') guard already prevents the
undefined-function fatal, and the function emits no warnings in normal
operation, so the @ suppression on the call is dead weight. Removing it
also keeps both halves of this fix consistent (the protector.php change
has no @) and matches the PR's own rationale that @ is misleading here.

Addresses CodeRabbit review feedback on PR XOOPS#60.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@mambax7 mambax7 merged commit 4990264 into XOOPS:master May 15, 2026
10 of 12 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 15, 2026
3 tasks
mambax7 added a commit that referenced this pull request May 15, 2026
Add Installer and Tests subsections under 2.7.0 Final for the work
merged today:

- #60 guard optional function calls that fatal on PHP 8.2
  (mysqli_get_client_info(), Protector config cache)
- #62 block install with a clear message when a mandatory PHP
  extension is missing, plus full required-extension guards on the
  DB steps
- #63 unit coverage for the installer required-extension helpers
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.

2 participants