Symfony polyfills backporting features to lower PHP versions
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.
Polyfills are provided for:
apcuextension when the legacy
apcextension is installed;
Normalizerclass and the
utf8_decodefunctions from the
SessionHandlerInterfaceclasses introduced in PHP 5.4;
hash_pbkdf2functions introduced in PHP 5.5;
password_*related functions introduced in PHP 5.5, provided by the
ldap_escapefunctions introduced in PHP 5.6;
intdivfunctions introduced in PHP 7.0;
is_iterablefunction introduced in PHP 7.1;
random_intfunctions introduced in PHP 7.0, provided by the
Binaryutility class to be used when compatibility with
It is strongly recommended to upgrade your PHP version and/or install the missing extensions whenever possible. This polyfill should be used only when there is no better choice or when portability is a requirement.
To write portable code between PHP5 and PHP7, some care must be taken:
\*Errorexceptions must be caught before
- after calling
error_clear_last(), the result of
$e = error_get_last()must be verified using
null === $e.
When using Composer to manage your dependencies, you
symfony/polyfill package, but the standalone ones:
symfony/polyfill-apcufor using the
symfony/polyfill-php54for using the PHP 5.4 functions,
symfony/polyfill-php55for using the PHP 5.5 functions,
symfony/polyfill-php56for using the PHP 5.6 functions,
symfony/polyfill-php70for using the PHP 7.0 functions,
symfony/polyfill-php71for using the PHP 7.1 functions,
symfony/polyfill-iconvfor using the iconv functions,
symfony/polyfill-intl-graphemefor using the
symfony/polyfill-intl-icufor using the intl functions and classes,
symfony/polyfill-intl-normalizerfor using the intl normalizer,
symfony/polyfill-mbstringfor using the mbstring functions,
symfony/polyfill-utilfor using the polyfill utility helpers,
symfony/polyfill-xmlfor using the
symfony/polyfill directly would prevent Composer from sharing
correctly polyfills in dependency graphs. As such, it would likely install
more code than required.
This package is designed for low overhead and high quality polyfilling.
It adds only a few lightweight
require statements to the bootstrap process
to support all polyfills. Implementations are then loaded on-demand when
needed during code execution.
Polyfills are unit-tested alongside their native implementation so that feature and behavior parity can be proven and enforced in the long run.
This library is released under the MIT license.