PHPackages                             colopl/colopl\_bc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. colopl/colopl\_bc

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

colopl/colopl\_bc
=================

PHP Backwards compatibility library.

v12.0.2(1mo ago)2014.1k↓34.6%3[1 PRs](https://github.com/colopl/php-colopl_bc/pulls)PHP-3.01PHPPHP ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.1 || ~8.5.0CI failing

Since Jun 12Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/colopl/php-colopl_bc)[ Packagist](https://packagist.org/packages/colopl/colopl_bc)[ RSS](/packages/colopl-colopl-bc/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (26)Used By (0)

colopl\_bc
==========

[](#colopl_bc)

Provides various compatibility functions required for PHP (temporary) migration.

Warning

This extension is intended for temporary use only. In other words, code in the production environment should not rely on this implementation as much as possible, and should be gradually phased out when it is safe to do so.

Supported Versions
------------------

[](#supported-versions)

- Extension: PHP &gt;= 8.0, 8.4 &gt;= PHP
- Library: PHP &gt;= 7.4, 8.4 &gt;= PHP

Library is introduced for migration to PHP 8.x with the same code base. If you do not need to work with the same code base, you can use only the Extension.

Usage
-----

[](#usage)

### Install

[](#install)

This repository contains an Extension that provides the main compatibility and an assisting Library, each of which must be installed separately.

Extension can be installed in the following steps. Note that the PHP common build tool chain is required.

```
$ cd "ext"
$ phpize
$ ./configure
$ make -j$(nproc)
$ make test
$ sudo make install
```

Don't forget to enable extension. (Maybe create a `*.ini` file or use `docker-php-ext-enable`)

```
$ echo "extension=colopl_bc" | sudo tee "$(php-config --ini-dir)/10-colopl_bc.ini"
$ php -m | grep "colopl_bc"
colopl_bc
```

The library is installed in the following steps.

```
$ composer require "colopl/colopl_bc"
```

**Be sure to keep the Extension and Library the same version.**

### Code conversion with Rector

[](#code-conversion-with-rector)

The `colopl/colopl_bc` package contains Rector rules to convert your code to the functions provided by the existing `ext-colopl_bc`. This can be utilized to save time when dealing with large code bases.

For each rule, check the rule definition file `src/Rector`. The most common configuration for migrating from PHP 7.x to 8.x is as follows:

```
rules([
        SwitchCaseToEqualRector::class,
        ArrayFuncToBCMigrateRector::class,
        SortToBCMigrateRector::class,
        EqualToBCMigrateRector::class,
        GreaterToBCMigrateRector::class,
        GreaterOrEqualToBCMigrateRector::class,
        NotEqualToBCMigrateRector::class,
        SmallerToBCMigrateRector::class,
        SmallerOrEqualToBCMigrateRector::class,
        SpaceshipToBCMigrateRector::class
    ]);
/* ~~~ */
```

API references
--------------

[](#api-references)

### INI directives

[](#ini-directives)

#### `colopl_bc.php74.compare_mode` (default: `0`)

[](#colopl_bcphp74compare_mode-default-0)

Sets the compatibility check mode for various comparison operators (e.g. `==`).

- 0 (`COLOPL_BC_PHP74_COMPARE_MODE_SILENT`)

It does not perform compatibility checks and always uses the results of older behavior. Suitable for use in production environments.

- 1 (`COLOPL_BC_PHP74_COMPARE_MODE_DEPRECATED`)

Compares the result with the result of a native PHP operator and raises an error equivalent to `E_DEPRECATED` if the results are different.

- 2 (`COLOPL_BC_PHP74_COMPARE_MODE_LOG`)

Compares the results of native PHP operators and sends a log to the running SAPI if the results are different.

#### `colopl_bc.php74.sort_mode` (default: `0`)

[](#colopl_bcphp74sort_mode-default-0)

Sets the compatibility check mode for various unstable sort algorithms.

- 0 (`COLOPL_BC_PHP74_COMPARE_MODE_SILENT`)

It does not perform compatibility checks and always uses the results of older behavior. Suitable for use in production environments.

- 1 (`COLOPL_BC_PHP74_COMPARE_MODE_DEPRECATED`)

Compares the result with the result of a native PHP function and raises an error equivalent to `E_DEPRECATED` if the results are different.

- 2 (`COLOPL_BC_PHP74_COMPARE_MODE_LOG`)

Compares the results of native PHP functions and sends a log to the running SAPI if the results are different.

### Constants

[](#constants)

Please check the settings of the corresponding ini directives.

- `COLOPL_BC_PHP74_COMPARE_MODE_SILENT` = 0
- `COLOPL_BC_PHP74_COMPARE_MODE_DEPRECATED` = 1
- `COLOPL_BC_PHP75_COMPARE_MODE_LOG` = 2
- `COLOPL_BC_PHP74_SORT_MODE_SILENT` = 0
- `COLOPL_BC_PHP74_SORT_MODE_DEPRECATED` = 1
- `COLOPL_BC_PHP75_SORT_MODE_LOG` = 2

### Functions

[](#functions)

- `Colopl\ColoplBc\Php74\ksort()`
- `Colopl\ColoplBc\Php74\krsort()`
- `Colopl\ColoplBc\Php74\asort()`
- `Colopl\ColoplBc\Php74\arsort()`
- `Colopl\ColoplBc\Php74\sort()`
- `Colopl\ColoplBc\Php74\rsort()`
- `Colopl\ColoplBc\Php74\usort()`
- `Colopl\ColoplBc\Php74\uasort()`
- `Colopl\ColoplBc\Php74\uksort()`
- `Colopl\ColoplBc\Php74\array_multisort()`

Sorting is performed using the previous unstable sorting algorithm.

These compatibilities can also be checked at runtime. See the `colopl_bc.php74.sort_mode` INI directive for details.

- `Colopl\ColoplBc\Php74\in_array()`
- `Colopl\ColoplBc\Php74\array_search()`
- `Colopl\ColoplBc\Php74\array_keys()`

These functions use older comparison algorithms than PHP 8.0 for their internal use.

These compatibilities can also be checked at runtime. See the `colopl_bc.php74.compare_mode` INI directive for details.

- `Colopl\ColoplBc\Php74\eq()` (`==`)
- `Colopl\ColoplBc\Php74\neq()` (`!=`)
- `Colopl\ColoplBc\Php74\lt()` (`=`)
- `Colopl\ColoplBc\Php74\spaceship()` (``)

For the corresponding comparison operator, returns results that reproduce the older behavior.

These compatibilities can also be checked at runtime. See the `colopl_bc.php74.compare_mode` INI directive for details.

- `Colopl\ColoplBc\Php70\srand()`

Seed random numbers.

Warning

`srand()` provided by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\rand()`

Generate random numbers.

Warning

`rand()` provided by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\getrandmax()`

Returns the maximum value that can be returned by a call to `Colopl\ColoplBc\Php70\rand()`.

Warning

`rand()` provided by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\shuffle()`

This function shuffles (randomizes the order of the elements in) an array.

Warning

`shuffle()` use `Colopl\ColoplBc\Php70\rand()` algorithm internally, by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\str_shuffle()`

str\_shuffle() shuffles a string. One permutation of all possible is created.

Warning

`str_shuffle()` use `Colopl\ColoplBc\Php70\rand()` algorighm internally, by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\array_rand()`

Picks one or more random entries out of an array, and returns the key (or keys) of the random entries.

Warning

`array_rand()` use `Colopl\ColoplBc\Php70\rand()` algorithm internally, by colopl\_bc are based on the glibc `srand()` / `rand()` algorithm. The results may differ from those of the non glibc environments, e.g. Alpine Linux.

- `Colopl\ColoplBc\Php70\mt_srand()`

Always initialize the state using a **broken** Mersenne twister.

- `Colopl\ColoplBc\Php70\mt_rand()`

Generate random numbers.

Warning

This function previously caused undefined behavior and returned different results depending on the CPU architecture. The current behavior is forced to mimic the gcc + amd64 results, and may return different results for PHP in other environments.

- `Colopl\ColoplBc\Php70\date_create()`
- `Colopl\ColoplBc\Php70\date_create_immutable()`

Always instantiate DateTime without milliseconds.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 78% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~78 days

Recently: every ~98 days

Total

14

Last Release

52d ago

Major Versions

10.1.0 → 11.0.02024-03-26

11.1.0 → v12.0.02025-12-03

PHP version history (5 changes)10.0.0PHP ~7.4.0 || ~8.0.0 || ~8.1.0

10.0.1PHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0

11.0.0PHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0

11.0.3PHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.1

v12.0.0PHP ~7.4.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.1 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec4f701f1c6b107218dbe17f7218ab1b9ff2889e7a543ab4065aba59786ac874?d=identicon)[COLOPL, Inc.](/maintainers/COLOPL,%20Inc.)

---

Top Contributors

[![zeriyoshi](https://avatars.githubusercontent.com/u/10289597?v=4)](https://github.com/zeriyoshi "zeriyoshi (46 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")[![siketyan](https://avatars.githubusercontent.com/u/12772118?v=4)](https://github.com/siketyan "siketyan (1 commits)")

---

Tags

extensionlibraryphpphp7php8

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/colopl-colopl-bc/health.svg)

```
[![Health](https://phpackages.com/badges/colopl-colopl-bc/health.svg)](https://phpackages.com/packages/colopl-colopl-bc)
```

###  Alternatives

[optimistdigital/nova-multiselect-field

A multiple select field for Laravel Nova.

3403.5M7](/packages/optimistdigital-nova-multiselect-field)[symfony/semaphore

Symfony Semaphore Component

373.9M6](/packages/symfony-semaphore)[crell/fp

Functional utilities for PHP 8 and later

91429.8k11](/packages/crell-fp)[php-stubs/wordpress-globals

Global variables and global constants from WordPress core.

13799.0k17](/packages/php-stubs-wordpress-globals)[instaclick/symfony2-coding-standard

A code standard to check against the Symfony coding standards.

1048.5k13](/packages/instaclick-symfony2-coding-standard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
