Skip to content

Conversation

@mambax7
Copy link
Collaborator

@mambax7 mambax7 commented Jan 1, 2026

No description provided.

…instead

fix offset is deprecated, use an empty string instead
replacing extract()
Copy link
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

This PR addresses PHP deprecation warnings related to using null as an array offset by replacing extract() calls with explicit variable extraction and adding validation checks before using variables as array keys.

Key changes:

  • Replaced extract() calls in config() and write() methods with explicit array key checking and assignment
  • Added string type and empty string validation before using variables as array offsets
  • Updated parameter documentation to reflect that null values are accepted

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 112 to 116
if (isset($name['name']) && is_string($name['name'])) {
$name = $name['name'];
}
if (isset($name['settings']) && is_array($name['settings'])) {
$settings = array_merge($settings, $name['settings']);
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

After reassigning $name to a string on line 113, the code attempts to access $name['settings'] on line 115. This will cause a "Cannot use a scalar value as an array" error. The original array should be preserved in a separate variable before extracting values from it.

Suggested change
if (isset($name['name']) && is_string($name['name'])) {
$name = $name['name'];
}
if (isset($name['settings']) && is_array($name['settings'])) {
$settings = array_merge($settings, $name['settings']);
$config = $name;
if (isset($config['name']) && is_string($config['name'])) {
$name = $config['name'];
}
if (isset($config['settings']) && is_array($config['settings'])) {
$settings = array_merge($settings, $config['settings']);

Copilot uses AI. Check for mistakes.

$config = $_this->config($config);


Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

Extra blank line. There are two consecutive blank lines here which is inconsistent with the rest of the codebase.

Suggested change

Copilot uses AI. Check for mistakes.
Copy link
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 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


$config = $_this->config($config);


Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

Extra blank line should be removed for code consistency.

Suggested change

Copilot uses AI. Check for mistakes.
}

if (isset($config['settings']) && is_array($config['settings'])) {
$settings = array_merge($settings, $config['settings']);
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The behavior change from using extract to array_merge could introduce subtle bugs. The old code would completely replace settings with the value from the config array, but the new code merges them. If the intention is to maintain backward compatibility, line 119 should be changed to assign the settings directly rather than merging: $settings = $config['settings']; instead of $settings = array_merge($settings, $config['settings']);

Suggested change
$settings = array_merge($settings, $config['settings']);
$settings = $config['settings'];

Copilot uses AI. Check for mistakes.
Copy link
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 1 out of 1 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

htdocs/class/cache/xoopscache.php:435

  • Potential null array offset issue: When $_this->name is null (which is its initial value), accessing $_this->configs[$_this->name] will use null as an array key. This should be guarded with a null check on $_this->name before attempting array access, similar to the pattern used in the updated config method at lines 156-161.
        if (!$engine && isset($_this->configs[$_this->name]['engine'])) {
            $engine = $_this->configs[$_this->name]['engine'];
        }

htdocs/class/cache/xoopscache.php:451

  • Potential null array offset issue: When $_this->name is null (which is its initial value), accessing $_this->configs[$_this->name] will use null as an array key. This should be guarded with a null check on $_this->name before attempting array access, similar to the pattern used in the updated config method at lines 156-161.
        if (!$engine && isset($_this->configs[$_this->name]['engine'])) {
            $engine = $_this->configs[$_this->name]['engine'];

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 99 to 100


Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

Excessive blank lines: There are three consecutive blank lines (lines 99-100) which is inconsistent with the rest of the codebase that typically uses single blank lines between methods.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +336 to 339
$config = $_this->resolveEngineConfig($config);
if ($config === false) {
return false;
}
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

Inconsistent return type behavior: The method returns false when config resolution fails (line 338), but the PHPDoc at line 328 states the return type is mixed (cached data or false). While this is technically correct, it creates an ambiguity where false could mean either "config failed" or "cached data is false". Consider documenting this nuance or using a different sentinel value for configuration failures.

Copilot uses AI. Check for mistakes.
}

$engine = $config['engine'];

Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

Missing null check: The code assumes $_this->engine[$engine] exists and is not null before calling gc() on it. If the engine initialization failed (line 224 sets it to null), this will cause a fatal error. An isInitialized check should be added before accessing the engine, similar to the pattern used in write, read, delete, and clear methods.

Suggested change
if (!isset($_this->engine[$engine]) || $_this->engine[$engine] === null) {
return false;
}

Copilot uses AI. Check for mistakes.
Copy link
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 1 out of 1 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @var array<string, XoopsCacheEngine|null>
* @access protected
*/
protected $engine = [];
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The $engine property is now initialized as an empty array, but throughout the codebase it's used with string keys (e.g., $_this->engine[$name]). Consider adding a check in the engine() method to ensure that $_this->engine[$name] is not just isset() but also an instance of the expected cache engine class before calling methods on it, to prevent potential type errors if the array is manipulated incorrectly elsewhere.

Copilot uses AI. Check for mistakes.
*/
private function resolveEngineName($engine)
{
if (is_string($engine) && $engine !== '') {
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The validation $engine !== '' is checking for empty strings, but the parameter type allows string|null. Consider explicitly checking for null first ($engine !== null) before the string checks for clearer intent and to handle the null case distinctly from empty strings.

Suggested change
if (is_string($engine) && $engine !== '') {
if ($engine !== null && is_string($engine) && $engine !== '') {

Copilot uses AI. Check for mistakes.
Comment on lines 160 to 164
$config = $name;

if (isset($config['name']) && is_string($config['name'])) {
$name = $config['name'];
}
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

When $name is an array, it's assigned to $config, but if $config['name'] is not set or not a string, $name remains an array. This could lead to type errors in subsequent code that expects $name to be a string. Consider setting a default string value (e.g., 'default') if the name cannot be extracted from the config array.

Copilot uses AI. Check for mistakes.
}

if (isset($config['settings']) && is_array($config['settings'])) {
// Preserve legacy behavior: overwrite settings, do NOT merge
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The comment uses 'do NOT merge' for emphasis, but the standard style would be 'do not merge' without capitalization. Consider using consistent casing for better readability.

Suggested change
// Preserve legacy behavior: overwrite settings, do NOT merge
// Preserve legacy behavior: overwrite settings, do not merge

Copilot uses AI. Check for mistakes.
Comment on lines 276 to 281
// Check if engine is initialized before calling gc()
if (!$_this->isInitialized($engine)) {
trigger_error("Cache engine {$engine} not initialized for garbage collection", E_USER_WARNING);
return false;
}

Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The isInitialized() method now returns false if $engine is null (from resolveEngineName()). However, at line 274, $engine is extracted from the validated config, so it should always be a string. The check at line 277 is redundant given that resolveEngineConfig() already validates the engine. Consider removing this check or documenting why it's necessary despite the earlier validation.

Suggested change
// Check if engine is initialized before calling gc()
if (!$_this->isInitialized($engine)) {
trigger_error("Cache engine {$engine} not initialized for garbage collection", E_USER_WARNING);
return false;
}

Copilot uses AI. Check for mistakes.
Comment on lines 473 to 475
return is_string($engine)
&& isset($_this->engine[$engine])
&& $_this->engine[$engine] !== null;
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The triple condition check is_string($engine) && isset($_this->engine[$engine]) && $_this->engine[$engine] !== null could be simplified. If $engine is null or not a string, the isset() check would return false anyway. Consider reordering to is_string($engine) && !empty($_this->engine[$engine]) for conciseness, though this changes semantics slightly if the engine value is falsy but not null.

Copilot uses AI. Check for mistakes.
Copy link
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 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


$engine = $config['engine'];

// Engine configuration is valid, but runtime initialization may have failed
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

Comment formatting is inconsistent with project standards. There should be a space after the double slashes in inline comments.

Suggested change
// Engine configuration is valid, but runtime initialization may have failed
// Engine configuration is valid, but runtime initialization may have failed

Copilot uses AI. Check for mistakes.
* @package core
* @subpackage cache
* @since 2.5.12
* @deprecated 4.0.0 Use Xoops\Core\Cache\EngineInterface instead
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The deprecation notice refers to version "4.0.0" which appears to be a hypothetical future version. While this is acceptable for deprecation notices indicating long-term plans, consider whether a more concrete version number should be used if the deprecation timeline is known, or add a note explaining this is a planned future major version.

Suggested change
* @deprecated 4.0.0 Use Xoops\Core\Cache\EngineInterface instead
* @deprecated 4.0.0 (planned future major version) Use Xoops\Core\Cache\EngineInterface instead

Copilot uses AI. Check for mistakes.
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