Symfony Polyfill

repository·1.x·Indexed 25 days ago

https://github.com/symfony/polyfill

Provides backported features from newer PHP versions (including PHP 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, and 8.4) and compatibility layers for missing extensions such as apcu, ctype, deepclone, iconv, mbstring, uuid, and various intl components. It enables developers to write modern PHP code that remains portable across older environments. The library is distributed as a set of standalone packages to optimize dependency graphs and minimize overhead.

Tokens
4.2K
Snippets
3
Records
35
Agent score
83%

What's inside symfony/polyfill

  1. Overview of polyfilled features

    1.x

    Symfony Polyfill backports features from recent PHP versions and provides compatibility layers for missing extensions.

    Key Backported Features include (but are not limited to):

    • PHP 8.0+: str_contains, str_starts_with, str_ends_with, ValueError, Attribute, Stringable.
    • PHP 8.1+: array_is_list, enum_exists, ReturnTypeWillChange.
    • PHP 8.2+: AllowDynamicProperties, SensitiveParameter, Random\Engine.
    • PHP 8.3+: json_validate, Override attribute.
    • PHP 8.4+: array_find, array_any, array_all, mb_ucfirst, mb_lcfirst.
    • Extensions: apcu, ctype, deepclone, mbstring, iconv, uuid, intl (various components), grapheme, idn.
  2. Use PHP 8.5 features via symfony/polyfill-php85

    1.x

    This polyfill component provides compatibility for features introduced in PHP 8.5. It allows you to use the following functions and classes on older PHP versions:

    • get_error_handler() and get_exception_handler()
    • NoDiscard attribute
    • array_first() and array_last()
    • DelayedTargetValidation attribute
    • Filter\FilterException class
    • Filter\FilterFailedException class
    • locale_is_right_to_left()
  3. Use the Iconv polyfill for PHP iconv functions

    1.x
    This component provides a native PHP implementation of the php.net/iconv functions. It allows you to use iconv functionality even if the iconv extension is not installed on your system. Note that ob_iconv_handler is not supported by this polyfill.
  4. Use UUID functions without the PHP uuid extension

    1.x
    The symfony/polyfill/uuid component provides the uuid_* functions for environments where the PHP uuid extension is not installed. This allows you to use standard UUID functions in older or restricted PHP environments.
  5. Use PHP 8.1 features via Symfony Polyfill

    1.x

    This polyfill provides compatibility for several features introduced in PHP 8.1. It allows you to use these functions, constants, and classes on older PHP versions without triggering errors.

    Supported features include:

    • array_is_list(): Checks if an array is a list (sequential integer keys starting from 0).
    • enum_exists(): Checks if an enum exists.
    • MYSQLI_REFRESH_REPLICA constant: A mysqli constant.
    • ReturnTypeWillChange attribute: Used to suppress deprecation warnings when a return type is not specified in a way that matches the parent class/interface.
    • CURLStringFile class: Provides a way to use a string as a file for CURL operations (requires PHP >= 7.4).
  6. Use the PHP 7.4 Polyfill component

    1.x

    This component provides polyfills for specific functions introduced in the PHP 7.4 core. It allows your application to use these functions even when running on older PHP versions.

    Supported functions include:

    • get_mangled_object_vars()
    • mb_str_split()
    • password_algos()
  7. Use PHP 8.4 features via Symfony Polyfill

    1.x

    The symfony/polyfill component provides backports for features introduced in PHP 8.4. If you are running a PHP version older than 8.4, you can install this polyfill to gain access to the following functions, constants, and classes:

    Array Functions

    • array_find
    • array_find_key
    • array_any
    • array_all

    BCMath

    • bcdivmod

    Attributes

    • Deprecated attribute

    Curl Constants

    • CURL_HTTP_VERSION_3
    • CURL_HTTP_VERSION_3ONLY

    Math Functions

    • fpow

    Grapheme Functions

    • grapheme_str_split

    Multibyte String (mbstring) Functions

    • mb_trim
    • mb_ltrim
    • mb_rtrim
    • mb_ucfirst
    • mb_lcfirst

    PDO

    • PDO driver specific sub-classes

    Reflection

    • ReflectionConstant class
  8. Use Intl Grapheme polyfill functions

    1.x

    This component provides a partial, native PHP implementation of the Grapheme functions from the Intl extension. It allows you to work with grapheme clusters in UTF-8 encoded text even if the intl extension is not installed or does not support these specific functions.

    Supported functions include:

    • grapheme_extract: Extract a sequence of grapheme clusters from a UTF-8 text buffer.
    • grapheme_stripos: Find the position (in grapheme units) of the first occurrence of a case-insensitive string.
    • grapheme_stristr: Returns part of a haystack string from the first occurrence of a case-insensitive needle to the end of the haystack.
    • grapheme_strlen: Get the string length in grapheme units.
    • grapheme_strpos: Find the position (in grapheme units) of the first occurrence of a string.
    • grapheme_strripos: Find the position (in grapheme units) of the last occurrence of a case-insensitive string.
    • grapheme_strrpos: Find the position (in grapheme units) of the last occurrence of a string.
    • grapheme_strstr: Returns part of a haystack string from the first occurrence of a needle to the end of the haystack.
    • grapheme_substr: Return part of a string.
    • grapheme_str_split: Splits a string into an array of individual graphemes or chunks of graphemes.
  9. Use the Ctype polyfill

    1.x
    The symfony/polyfill-ctype component provides ctype_* functions for PHP environments where the ctype extension is not installed or enabled. This allows your code to use character type checking functions reliably across different PHP versions and configurations.
  10. Use PHP 8.3 features via Symfony Polyfill

    1.x

    If you are running a PHP version older than 8.3, you can use this polyfill to access several features introduced in the PHP 8.3 core. This includes functions, classes, and language behaviors such as:

    • json_validate: Validates a JSON string without decoding it.
    • Override attribute: Marks methods that are intended to override a parent method.
    • mb_str_pad: Multi-byte string padding.
    • ldap_exop_sync and ldap_connect_wallet: LDAP functions.
    • stream_context_set_options: Stream context management.
    • str_increment and str_decrement: String increment/decrement operators.
    • Date*Exception and Error classes: Specialized datetime exceptions.
    • SQLite3Exception: SQLite3 error handling.