Production-ready PHP compatibility files for developers upgrading old PHP applications to PHP 8.0, PHP 8.1, PHP 8.2, and PHP 8.3.
This project helps fix real migration breakage caused by removed functions, deprecated behavior, and stricter runtime rules in modern PHP. It is designed for legacy WordPress themes and plugins, old Laravel applications, Symfony legacy bundles, CodeIgniter 2 and 3 projects, Magento 1 and legacy Magento codebases, and custom PHP frameworks or enterprise systems that still depend on PHP 5.x and PHP 7.x behavior.
Upgrading old PHP code to PHP 8 often causes immediate fatal errors and behavioral regressions:
create_function()removedeach()removedereg(),eregi(),ereg_replace(),eregi_replace()removedsplit()andspliti()removedutf8_encode()andutf8_decode()removedstrftime()andgmstrftime()deprecatedcount(null)and similar loose calls now fail or throw- old
implode()argument order no longer works - old array, string, regex, and session assumptions break under PHP 8 strictness
This repository provides:
- removed function polyfills where behavior can be reproduced honestly
- documented approximations where full restoration is impossible
- safe migration helpers for stricter PHP 8 behavior
- two compatibility modes for different risk tolerance levels
php-legacy-compat-universal.php is the broader compatibility layer.
Use it when:
- you are migrating a difficult legacy application
- the priority is keeping old code operational on PHP 8
- you need broader compatibility coverage for old plugins, themes, packages, or custom systems
The universal build includes practical approximations where that is still honest and useful, such as broader migration helpers and a documented money_format() polyfill.
php-legacy-compat-strict.php is the conservative compatibility layer.
Use it when:
- you want safer and more controlled migration behavior
- you prefer fewer approximations
- you want compatibility help without enabling looser edge-case behavior
The strict build omits behavior that is too approximate or too risky for a conservative default, such as money_format(), and tightens helpers like legacy_safe_count(), legacy_safe_implode(), legacy_safe_array_merge(), and legacy_safe_array_key_exists().
- PHP 8 compatibility layer for legacy applications
- Legacy PHP support for PHP 5.x and PHP 7.x code running on PHP 8
- WordPress compatibility for old themes, plugins, and mu-plugins
- Laravel legacy support for older apps and packages
- Symfony legacy support for older bundles and utility code
- CodeIgniter compatibility for CodeIgniter 2 and CodeIgniter 3 projects
- Magento and Magento 1 compatibility support for legacy integrations
- Removed function polyfills for classic migration failures
- Deprecated function replacements and migration helpers
- Safe PHP 8 migration helpers for string, array, regex, and counting behavior
- Optional diagnostics and optional soft error handling for staged migrations
This project covers realistic compatibility for removed and deprecated behavior including:
create_function()each()split()spliti()sql_regcase()ereg()eregi()ereg_replace()eregi_replace()session_register()session_unregister()session_is_registered()utf8_encode()utf8_decode()- magic quotes reporting fallbacks
strftime()andgmstrftime()replacement helpers- PHP 8 migration helpers such as
legacy_safe_count(),legacy_safe_implode(),legacy_safe_explode(), andlegacy_safe_preg_replace()
Choose one file and include it as early as possible in your application bootstrap.
require_once __DIR__ . '/php-legacy-compat-universal.php';Or:
require_once __DIR__ . '/php-legacy-compat-strict.php';For WordPress, place the chosen file in wp-content/mu-plugins/ or require it from a small loader file that runs before older themes and plugins.
Examples:
public/index.phpbootstrap/app.phpconfig/bootstrap.php- a front controller used by a custom framework
Install the package:
composer require infinitumform/php-legacy-compatThen include exactly one compatibility file in your bootstrap:
require_once __DIR__ . '/vendor/infinitumform/php-legacy-compat/php-legacy-compat-universal.php';Or:
require_once __DIR__ . '/vendor/infinitumform/php-legacy-compat/php-legacy-compat-strict.php';The two compatibility files are intentionally mutually exclusive:
php-legacy-compat-universal.phpphp-legacy-compat-strict.php
Auto-loading both through Composer autoload.files would be the wrong design because it would attempt to load two different compatibility policies in the same process. For that reason, this package stays manual-include by design after Composer installation.
That is the correct behavior for:
- WordPress mu-plugins
- Laravel bootstrap files
- Symfony entry points
- CodeIgniter front controllers
- Magento bootstraps
- custom PHP framework loaders
Use the universal file for hard migrations and old applications that must keep running while you modernize the codebase incrementally.
require_once __DIR__ . '/php-legacy-compat-universal.php';Use the strict file when you want compatibility help but still want tighter and more predictable behavior.
require_once __DIR__ . '/php-legacy-compat-strict.php';$report = legacy_compat_get_report();
print_r($report);The error handler is opt-in only.
legacy_compat_register_soft_error_handler();Old callback code:
$callback = create_function('$value', 'return trim($value);');Modern PHP:
- fatal error because
create_function()is gone
This project restores a generated callable name string so old callback registration patterns can continue to work.
Old code:
while (list($key, $value) = each($data)) {
// ...
}Modern PHP:
- fatal error because
each()was removed
This project restores the classic array-pointer behavior.
Old code:
if (ereg('^[0-9]+$', $value)) {
// ...
}Modern PHP:
- fatal error because POSIX regex functions were removed
This project provides documented PCRE-backed approximations for the old POSIX regex family.
Old code:
if (count($items)) {
// ...
}Modern PHP:
- warnings or TypeError depending on the input and PHP version
This project provides helpers like:
if (legacy_safe_count($items)) {
// ...
}Old code:
echo implode($array, ',');Modern PHP:
- invalid in PHP 8
This project provides:
echo legacy_safe_implode($array, ',');This repository follows an honest compatibility philosophy:
- no fake success values
- no fake extension recreation
- no fake magic quotes engine state
- no silent data corruption disguised as compatibility
- no stub that just returns
falsewhen realistic behavior can actually be recreated
If something cannot be reproduced exactly in userland, the limitation is documented clearly.
This repository is intended for GitHub Releases and Packagist distribution.
The first stable release is:
v1.0.0
This project follows semantic versioning:
- patch releases for documentation fixes, metadata cleanup, non-breaking compatibility fixes, and safe internal corrections
- minor releases for new helpers, new non-breaking polyfills, new documentation, and expanded compatibility coverage that does not break existing consumers
- major releases for breaking behavior changes, removed APIs, renamed files, or compatibility-policy changes that can affect existing bootstrap logic
- create a Git tag for each release
- publish matching GitHub Releases
- keep
CHANGELOG.mdupdated for every tagged version - prefer stable tags for Packagist indexing and Composer consumers
See CHANGELOG.md for release history.
| Legacy Code Origin | Runtime Target | Status |
|---|---|---|
| PHP 5.x | PHP 8.0 to 8.3 | Supported through compatibility layers and migration helpers |
| PHP 7.x | PHP 8.0 to 8.3 | Supported through removed-function handling and migration helpers |
| PHP 8.0 | PHP 8.1 to 8.3 | Supported with deprecation-aware helpers |
| PHP 8.1 | PHP 8.2 to 8.3 | Supported with deprecated function replacements |
| PHP 8.2 | PHP 8.3 | Supported with migration helpers and polyfills where needed |
This project is not limited to WordPress.
It is especially useful for:
- WordPress legacy themes and plugins
- Laravel legacy apps and old packages
- Symfony legacy bundles and internal libraries
- CodeIgniter 2 and CodeIgniter 3 applications
- Magento 1 and legacy Magento integrations
- Custom PHP frameworks
- Legacy enterprise PHP systems
- Older internal tools, CRMs, admin panels, and proprietary stacks
php-legacy-compat-universal.php
php-legacy-compat-strict.php
README.md
LICENSE
CONTRIBUTING.md
CHANGELOG.md
composer.json
docs/
Author: Ivijan-Stefan Stipić
LinkedIn: https://www.linkedin.com/in/ivijanstefanstipic/
Senior Full-Stack Developer focused on performance, systems architecture, and large-scale PHP applications.
This project is licensed under the MIT License. See LICENSE.
- php 8 compatibility
- php 8 deprecated functions
- php create_function removed
- php each removed
- php ereg alternative
- php migration tool
- wordpress php 8 fix
- legacy php support
- php upgrade issues
