• Stars
    star
    2,468
  • Rank 18,628 (Top 0.4 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP polyfills

Symfony Polyfill

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:

  • the apcu extension when the legacy apc extension is installed;
  • the ctype extension when PHP is compiled without ctype;
  • the mbstring and iconv extensions;
  • the uuid extension;
  • the MessageFormatter class and the msgfmt_format_message functions;
  • the Normalizer class and the grapheme_* functions;
  • the utf8_encode and utf8_decode functions from the xml extension or PHP-7.2 core;
  • the Collator, NumberFormatter, Locale and IntlDateFormatter classes, limited to the "en" locale;
  • the intl_error_name, intl_get_error_code, intl_get_error_message and intl_is_failure functions;
  • the idn_to_ascii and idn_to_utf8 functions;
  • the hex2bin function, the CallbackFilterIterator, RecursiveCallbackFilterIterator and SessionHandlerInterface classes introduced in PHP 5.4;
  • the array_column, boolval, json_last_error_msg and hash_pbkdf2 functions introduced in PHP 5.5;
  • the password_hash and password_* related functions introduced in PHP 5.5, provided by the ircmaxell/password-compat package;
  • the hash_equals and ldap_escape functions introduced in PHP 5.6;
  • the *Error classes, the error_clear_last, preg_replace_callback_array and intdiv functions introduced in PHP 7.0;
  • the random_bytes and random_int functions introduced in PHP 7.0, provided by the paragonie/random_compat package;
  • the PHP_INT_MIN constant introduced in PHP 7.0,
  • the SessionUpdateTimestampHandlerInterface interface introduced in PHP 7.0,
  • the is_iterable function introduced in PHP 7.1;
  • a Binary utility class to be used when compatibility with mbstring.func_overload is required;
  • the spl_object_id and stream_isatty functions introduced in PHP 7.2;
  • the mb_ord, mb_chr and mb_scrub functions introduced in PHP 7.2 from the mbstring extension
  • the sapi_windows_vt100_support function (Windows only) introduced in PHP 7.2;
  • the PHP_FLOAT_* constant introduced in PHP 7.2;
  • the PHP_OS_FAMILY constant introduced in PHP 7.2;
  • the is_countable function introduced in PHP 7.3;
  • the array_key_first and array_key_last functions introduced in PHP 7.3;
  • the hrtime function introduced in PHP 7.3;
  • the JsonException class introduced in PHP 7.3;
  • the get_mangled_object_vars, mb_str_split and password_algos functions introduced in PHP 7.4;
  • the fdiv function introduced in PHP 8.0;
  • the get_debug_type function introduced in PHP 8.0;
  • the preg_last_error_msg function introduced in PHP 8.0;
  • the str_contains function introduced in PHP 8.0;
  • the str_starts_with and str_ends_with functions introduced in PHP 8.0;
  • the ValueError class introduced in PHP 8.0;
  • the UnhandledMatchError class introduced in PHP 8.0;
  • the FILTER_VALIDATE_BOOL constant introduced in PHP 8.0;
  • the get_resource_id function introduced in PHP 8.0;
  • the Attribute class introduced in PHP 8.0;
  • the Stringable interface introduced in PHP 8.0;
  • the PhpToken class introduced in PHP 8.0 when the tokenizer extension is enabled;
  • the array_is_list function introduced in PHP 8.1;
  • the enum_exists function introduced in PHP 8.1;
  • the MYSQLI_REFRESH_REPLICA constant introduced in PHP 8.1;
  • the ReturnTypeWillChange attribute introduced in PHP 8.1;
  • the CURLStringFile class introduced in PHP 8.1 (but only if PHP >= 7.4 is used);
  • the AllowDynamicProperties attribute introduced in PHP 8.2;
  • the SensitiveParameter attribute introduced in PHP 8.2;
  • the SensitiveParameterValue class introduced in PHP 8.2;
  • the Random\Engine interface introduced in PHP 8.2;
  • the Random\CryptoSafeEngine interface introduced in PHP 8.2;
  • the Random\Engine\Secure class introduced in PHP 8.2 (check arokettu/random-polyfill for more engines);
  • the odbc_connection_string_is_quoted function introduced in PHP 8.2;
  • the odbc_connection_string_should_quote function introduced in PHP 8.2;
  • the odbc_connection_string_quote function introduced in PHP 8.2;
  • the json_validate function introduced in PHP 8.3;
  • the Override attribute introduced in PHP 8.3;
  • the mb_str_pad function introduced in PHP 8.3;
  • the ldap_exop_sync function introduced in PHP 8.3;
  • the ldap_connect_wallet function introduced in PHP 8.3;
  • the stream_context_set_options function introduced in PHP 8.3;
  • the Date*Exception/Error classes introduced in PHP 8.3;

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.

Compatibility notes

To write portable code between PHP5 and PHP7, some care must be taken:

  • \*Error exceptions must be caught before \Exception;
  • after calling error_clear_last(), the result of $e = error_get_last() must be verified using isset($e['message'][0]) instead of null !== $e.

Usage

When using Composer to manage your dependencies, you should not require the symfony/polyfill package, but the standalone ones:

  • symfony/polyfill-apcu for using the apcu_* functions,
  • symfony/polyfill-ctype for using the ctype functions,
  • symfony/polyfill-php54 for using the PHP 5.4 functions,
  • symfony/polyfill-php55 for using the PHP 5.5 functions,
  • symfony/polyfill-php56 for using the PHP 5.6 functions,
  • symfony/polyfill-php70 for using the PHP 7.0 functions,
  • symfony/polyfill-php71 for using the PHP 7.1 functions,
  • symfony/polyfill-php72 for using the PHP 7.2 functions,
  • symfony/polyfill-php73 for using the PHP 7.3 functions,
  • symfony/polyfill-php74 for using the PHP 7.4 functions,
  • symfony/polyfill-php80 for using the PHP 8.0 functions,
  • symfony/polyfill-php81 for using the PHP 8.1 functions,
  • symfony/polyfill-php82 for using the PHP 8.2 functions,
  • symfony/polyfill-php83 for using the PHP 8.3 functions,
  • symfony/polyfill-iconv for using the iconv functions,
  • symfony/polyfill-intl-grapheme for using the grapheme_* functions,
  • symfony/polyfill-intl-idn for using the idn_to_ascii and idn_to_utf8 functions,
  • symfony/polyfill-intl-icu for using the intl functions and classes,
  • symfony/polyfill-intl-messageformatter for using the intl messageformatter,
  • symfony/polyfill-intl-normalizer for using the intl normalizer,
  • symfony/polyfill-mbstring for using the mbstring functions,
  • symfony/polyfill-util for using the polyfill utility helpers.
  • symfony/polyfill-uuid for using the uuid_* functions,

Requiring symfony/polyfill directly would prevent Composer from sharing correctly polyfills in dependency graphs. As such, it would likely install more code than required.

Design

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.

If your project requires a minimum PHP version it is advisable to add polyfills for lower PHP versions to the replace section of your composer.json. This removes any overhead from these polyfills as they are no longer part of your project. The same can be done for polyfills for extensions that you require.

If your project requires php 7.0, and needs the mb extension, the replace section would look something like this:

{
    "replace": {
        "symfony/polyfill-php54": "*",
        "symfony/polyfill-php55": "*",
        "symfony/polyfill-php56": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-mbstring": "*"
    }
}

Polyfills are unit-tested alongside their native implementation so that feature and behavior parity can be proven and enforced in the long run.

License

This library is released under the MIT license.

More Repositories

1

symfony

The Symfony PHP framework
PHP
28,665
star
2

console

Eases the creation of beautiful and testable command line interfaces
PHP
9,560
star
3

http-foundation

Defines an object-oriented layer for the HTTP specification
PHP
8,513
star
4

event-dispatcher

Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
PHP
8,393
star
5

finder

Finds files and directories via an intuitive fluent interface
PHP
8,290
star
6

http-kernel

Provides a structured process for converting a Request into a Response
PHP
7,980
star
7

thanks

Give thanks (in the form of a GitHub ★) to your fellow PHP package maintainers (not limited to Symfony components)!
PHP
7,912
star
8

polyfill-mbstring

This component provides a partial, native PHP implementation for the Mbstring extension.
PHP
7,746
star
9

routing

Maps an HTTP request to a set of configuration variables
PHP
7,477
star
10

debug

Provides tools to ease debugging PHP code
PHP
7,312
star
11

css-selector

Converts CSS selectors to XPath expressions
PHP
7,309
star
12

process

Executes commands in sub-processes
PHP
7,302
star
13

var-dumper

Provides mechanisms for walking through any arbitrary PHP variable
PHP
7,278
star
14

translation

Provides tools to internationalize your application
PHP
6,529
star
15

polyfill-php72

This component provides functions added to PHP 7.2 core.
PHP
4,756
star
16

filesystem

Provides basic utilities for the filesystem
PHP
4,500
star
17

config

Helps you find, load, combine, autofill and validate configuration values of any kind
PHP
4,138
star
18

flex

Composer plugin for Symfony
PHP
4,043
star
19

dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application
PHP
4,011
star
20

cache

Provides extended PSR-6, PSR-16 (and tags) implementations
PHP
3,977
star
21

polyfill-ctype

This component provides a partial, native PHP implementation for the Ctype extension.
PHP
3,966
star
22

dom-crawler

Eases DOM navigation for HTML and XML documents
PHP
3,834
star
23

yaml

Loads and dumps YAML files
PHP
3,693
star
24

contracts

A set of abstractions extracted out of the Symfony components
PHP
3,607
star
25

dotenv

Registers environment variables from a .env file
PHP
3,604
star
26

framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework
PHP
3,402
star
27

maker-bundle

Symfony Maker Bundle
PHP
3,317
star
28

polyfill-php70

This component provides features unavailable in releases prior to PHP 7.0.
3,243
star
29

polyfill-intl-idn

This component provides a partial, native PHP implementation for the Intl extension (IDN features).
PHP
3,163
star
30

event-dispatcher-contracts

A set of event dispatcher abstractions extracted out of the Symfony components
PHP
3,146
star
31

doctrine-bridge

Provides integration for Doctrine with various Symfony components
PHP
3,086
star
32

options-resolver

Provides an improved replacement for the array_replace PHP function
PHP
3,074
star
33

asset

Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
PHP
3,046
star
34

browser-kit

Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
PHP
2,849
star
35

monolog-bundle

Symfony Monolog Bundle
PHP
2,817
star
36

panther

A browser testing and web crawling library for PHP and Symfony
PHP
2,742
star
37

expression-language

Provides an engine that can compile and evaluate expressions
PHP
2,709
star
38

stopwatch

Provides a way to profile code
PHP
2,692
star
39

property-access

Provides functions to read and write from/to an object or array using a simple string notation
PHP
2,677
star
40

form

Allows to easily create, process and reuse HTML forms
PHP
2,663
star
41

error-handler

Provides tools to manage errors and ease debugging PHP code
PHP
2,577
star
42

mime

Allows manipulating MIME messages
PHP
2,576
star
43

intl

Provides access to the localization data of the ICU library
PHP
2,560
star
44

polyfill-intl-icu

This component provides a collection of functions/classes using the symfony/intl package when the Intl extension is not installed.
PHP
2,537
star
45

validator

Provides tools to validate values
PHP
2,515
star
46

monolog-bridge

Provides integration for Monolog with various Symfony components
PHP
2,512
star
47

twig-bridge

Provides integration for Twig with various Symfony components
PHP
2,416
star
48

twig-bundle

Provides a tight integration of Twig into the Symfony full-stack framework
PHP
2,412
star
49

phpunit-bridge

Provides utilities for PHPUnit, especially user deprecation notices management
PHP
2,398
star
50

security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework
PHP
2,374
star
51

service-contracts

A set of service abstractions extracted out of the Symfony components
PHP
2,369
star
52

polyfill-php73

This component provides functions unavailable in releases prior to PHP 7.3.
PHP
2,367
star
53

translation-contracts

A set of translation abstractions extracted out of the Symfony components
PHP
2,362
star
54

serializer

Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
PHP
2,358
star
55

demo

Symfony Demo Application
PHP
2,345
star
56

debug-bundle

Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework
PHP
2,277
star
57

inflector

Converts words between their singular and plural forms (English only)
PHP
2,227
star
58

webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
JavaScript
2,225
star
59

cache-contracts

A set of cache abstractions extracted out of the Symfony components
PHP
2,149
star
60

web-profiler-bundle

Provides a development tool that gives detailed information about the execution of any request
Twig
2,147
star
61

property-info

Extracts information about PHP class' properties using metadata of popular sources
PHP
2,079
star
62

symfony-docs

The Symfony documentation
HTML
2,077
star
63

var-exporter

Allows exporting any serializable PHP data structure to plain PHP code
PHP
1,916
star
64

polyfill-intl-normalizer

This component provides a fallback implementation for the Normalizer class provided by the Intl extension.
PHP
1,840
star
65

orm-pack

A Symfony Pack for Doctrine ORM
1,839
star
66

http-client-contracts

A set of HTTP client abstractions extracted out of the Symfony components
PHP
1,770
star
67

http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously
PHP
1,763
star
68

polyfill-iconv

This component provides a native PHP implementation of the php.net/iconv functions.
PHP
1,757
star
69

deprecation-contracts

A generic function and convention to trigger deprecation notices
PHP
1,751
star
70

security-core

Symfony Security Component - Core Library
PHP
1,734
star
71

profiler-pack

A Symfony Pack for Symfony profiler
1,716
star
72

security-csrf

Symfony Security Component - CSRF Library
PHP
1,652
star
73

security-http

Symfony Security Component - HTTP Integration
PHP
1,580
star
74

polyfill-php80

This component provides functions unavailable in releases prior to PHP 8.0.
PHP
1,576
star
75

swiftmailer-bundle

Symfony Swiftmailer Bundle
PHP
1,571
star
76

polyfill-php56

This component provides functions unavailable in releases prior to PHP 5.6.
1,557
star
77

polyfill-intl-grapheme

This component provides a partial, native PHP implementation of the Grapheme functions from the Intl extension.
PHP
1,512
star
78

symfony-standard

The "Symfony Standard Edition" distribution
PHP
1,501
star
79

debug-pack

A Symfony Pack for Symfony debug
1,498
star
80

string

Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
PHP
1,447
star
81

security-guard

Symfony Security Component - Guard
PHP
1,434
star
82

polyfill-util

This component provides binary-safe string functions, using the mbstring extension when available.
PHP
1,338
star
83

web-link

Manages links between resources
PHP
1,333
star
84

web-server-bundle

Provides commands for running applications using the PHP built-in web server
PHP
1,280
star
85

mailer

Helps sending emails
PHP
1,263
star
86

psr-http-message-bridge

PSR HTTP message bridge
PHP
1,209
star
87

security

Provides a complete security system for your web application
PHP
1,203
star
88

class-loader

[DEPRECATED] The ClassLoader component provides tools to autoload your classes and cache their locations for performance.
PHP
1,109
star
89

serializer-pack

A Symfony Pack for Symfony Serializer
1,075
star
90

templating

Provides all the tools needed to build any kind of template system
PHP
1,021
star
91

webpack-encore-bundle

Symfony integration with Webpack Encore!
PHP
929
star
92

lts

Enforces Long Term Supported versions of Symfony components
924
star
93

messenger

Helps applications send and receive messages to/from other applications or via message queues
PHP
923
star
94

apache-pack

A Symfony Pack for Symfony Apache
913
star
95

recipes

Symfony Recipes Repository
PHP
908
star
96

test-pack

A Symfony Pack for functional testing
866
star
97

polyfill-php81

This component provides functions unavailable in releases prior to PHP 8.1.
PHP
764
star
98

proxy-manager-bridge

Provides integration for ProxyManager with various Symfony components
PHP
724
star
99

notifier

Sends notifications via one or more channels (email, SMS, ...)
PHP
673
star
100

polyfill-apcu

This component provides apcu_* functions and the APCUIterator class to users of the legacy APC extension.
PHP
635
star