Backwards compatibility Extension and Library for PHP 8.x and later

Overview

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

  • Extension: PHP >= 8.0, 8.2 >= PHP
  • Library: PHP >= 7.4, 8.2 >= 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

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

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:

<?php
/* ~~~ */
    $rectorConfig->rules([
        SwitchCaseToEqualRector::class,
        ArrayFuncToBCMigrateRector::class,
        SortToBCMigrateRector::class,
        EqualToBCMigrateRector::class,
        GreaterToBCMigrateRector::class,
        GreaterOrEqualToBCMigrateRector::class,
        NotEqualToBCMigrateRector::class,
        SmallerToBCMigrateRector::class,
        SmallerOrEqualToBCMigrateRector::class,
        SpaceshipToBCMigrateRector::class
    ]);
/* ~~~ */

API references

INI directives

colopl_bc.php74.compare_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)

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

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

  • 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\lte() (<=)
  • Colopl\ColoplBc\Php74\gt() (>)
  • Colopl\ColoplBc\Php74\gte() (>=)
  • 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.

You might also like...
Magento 2 Extension to cleanup admin menu and Store > Configuration area by arranging third party extension items.
Magento 2 Extension to cleanup admin menu and Store Configuration area by arranging third party extension items.

Clean Admin Menu - Magento 2 Extension It will merge all 3rd party extension's menu items in backend's primary menu to a common menu item named "Exten

Magento 2 Blog Extension is a better blog extension for Magento 2 platform. These include all useful features of Wordpress CMS
Magento 2 Blog Extension is a better blog extension for Magento 2 platform. These include all useful features of Wordpress CMS

Magento 2 Blog extension FREE Magento 2 Better Blog by Mageplaza is integrated right into the Magento backend so you can manage your blog and your e-c

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

PHP Meminfo is a PHP extension that gives you insights on the PHP memory content

MEMINFO PHP Meminfo is a PHP extension that gives you insights on the PHP memory content. Its main goal is to help you understand memory leaks: by loo

A PHP API extension the 'An API of Ice and Fire'

This documentation is meant to enable you to consume our API and get you started right away using your favourite programming language. All endpoints and HTTP methods to be used have been detailed with a sample example for e

Generate stubs for any PHP extension.

php-ext-stubs-generator Installation Run $ composer require --dev lctrs/php-ext-stubs-generator Usage $ php vendor/bin/generate-stubs-for-ext extensio

PHP Extension installer

pickle - PHP Extension installer Pickle installs PHP extensions easily on all platforms. Installation Grab the latest phar at https://github.com/Frien

PHP extension for V8 JavaScript engine

php-v8 PHP extension for V8 JavaScript engine This extension requires PHP = 7.2. Last version that supports PHP 7.1 is v0.2.2 and for PHP 7.0 is v0.1

Easily install PHP extension in Docker containers

Easy installation of PHP extensions in official PHP Docker images This repository contains a script that can be used to easily install a PHP extension

Check modules in app/code and vendor for PHP 8 compatibility status - PHP_CodeSniffer & php-compatibility standard

M2 PHP version compatibility check How To use Requires PHP 7.3+ | PHP 8 This app will run PHP_CodeSniffer with phpcompatibility/php-compatibility on t

William Tran 24 Oct 13, 2022
A Backwards Multi Version plugin for PocketMine-MP (API3)

MultiVersion A Backwards Multi Version plugin for PocketMine-MP (API3). This plugin is currently in development. Supported Versions 1.17.30 1.17.40 TO

null 81 Jan 7, 2023
Allow any Discord user to sign in to your website and save their discord user information for later use.

Simple Discord SSO ( Single Sign-On ) Requires at least: 5.0 Tested up to: 5.8.3 Stable tag: 1.0.2 Requires PHP: 7.4 License: GPLv2 or later License U

null 2 Oct 7, 2022
All about docker projects either from dockerfile or compose. Anyway, here the project is in the form of a service, for the programming language I will make it later

Docker Project by ItsArul Hey, yo guys okay, this time I made some projects from Docker. Anyway, this project is open source, for example, if you want

Kiyo 10 Nov 4, 2022
Disclaimer: The documentation of this plugin is English at the moment, but I might go for Latin later down the line, just for the fun of it.

Quiritibus Plugin This repository is storing the custom plugin developed for the Quiritibus Latin Magazine website, currently being developed at: http

Alkor András 1 Jan 19, 2022
Save items in a bucket, retrieve them later.

Bucket Save items in a bucket, retrieve them later. use Laragear\Bucket\Facades\Buckets; use App\Models\Message; public function send(Message $messag

Laragear 2 Jun 3, 2022
This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Symfony 2.2k Dec 29, 2022
PHP 7 Compatibility Checker

PHP 7 Compatibility Checker(php7cc) Project status The project is no longer supported. Please consider using one of the following alternatives: phan p

null 1.5k Dec 17, 2022
Silverstripe-sspy - Python based SSPAK export with higher reliability and cross-platform compatibility

SSPY - Python Stand-alone SSPAK solution © Simon Firesphere Erkelens; Moss Mossman Cantwell Usage: sspy [create|load|extract] (db|assets) --file=my.

Simon Erkelens 1 Jun 29, 2021
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).

JBZoo / CI-Report-Converter Why? Installing Using as GitHub Action Example GitHub Action workflow Available Directions Help description in terminal Co

JBZoo Toolbox 17 Jun 16, 2022