Handling Increment on Boolean Type in VersionManager.php

Hi,

I’ve encountered an issue in the VersionManager.php file of October CMS, which seems to arise from incrementing a boolean value.

Issue Description

In the VersionManager.php file, specifically at line 338, there’s an operation that increments a variable (++$position). The array_search function, used just before this increment operation, can return false if the specified version is not found in the array. Incrementing false is ineffective in PHP and will raise a warning in PHP 8.3, indicating that this behavior will change in future PHP versions.

Here’s the original code snippet for reference:

protected function getNewFileVersions($code, $version = null)
{
    if ($version === null) {
        $version = self::NO_VERSION_VALUE;
    }

    $versions = $this->getFileVersions($code);

    $position = array_search($version, array_keys($versions));

    return array_slice($versions, ++$position);
}

Proposed Solution

To address this, I’ve made a slight modification to check if $position is a boolean before incrementing it:

protected function getNewFileVersions($code, $version = null)
{
    if ($version === null) {
        $version = self::NO_VERSION_VALUE;
    }

    $versions = $this->getFileVersions($code);

    $position = array_search($version, array_keys($versions));

    if ($position === false) {
        return $versions;
    }

    $position++;

    return array_slice($versions, $position);
}

This change ensures that we don’t attempt to increment a boolean and handle the case where the specified version is not found more explicitly.

1 Like

Looks like this fix is implemented in version 3.5.13 :slight_smile:

1 Like