explaingit

symfony/polyfill-php72

4,748Audience · developerComplexity · 1/5LicenseSetup · easy

TLDR

Drop-in Symfony package that provides PHP 7.2 functions on older PHP 7.0 and 7.1 installations, so code written for PHP 7.2 runs on earlier versions without extra version-check conditionals.

Mindmap

mindmap
  root((polyfill-php72))
    What it does
      Backport PHP 7.2
      Fill missing functions
      No version checks needed
    Functions provided
      spl_object_id
      stream_isatty
      mb_ord and mb_chr
      mb_scrub
    Tech stack
      PHP
      Composer
    Use cases
      Legacy PHP support
      Symfony dependencies
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use PHP 7.2 functions like spl_object_id in a project that must still support PHP 7.0 or 7.1 servers.

USE CASE 2

Automatically receive PHP 7.2 compatibility as a transitive dependency when using modern Symfony components.

USE CASE 3

Clean up multibyte string encoding issues with mb_scrub without writing PHP-version-check code yourself.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 5min
MIT license, use freely for any purpose including commercial projects, as long as you keep the copyright notice.

In plain English

This package is a polyfill for PHP 7.2. A polyfill is a piece of code that fills in missing functionality, so that code written for a newer version of a language can still run on an older version. If you have a project that runs on PHP 7.0 or 7.1 and you want to use functions that were introduced in PHP 7.2, this package provides those functions so they are available even on the older version. The specific functions it covers are small but sometimes needed. On any PHP installation it provides spl_object_id, which returns a unique integer identifier for a given object, and stream_isatty, which checks whether a given stream is connected to a terminal. It also provides several multibyte string functions: mb_ord and mb_chr for converting between characters and their numeric code points, and mb_scrub for cleaning up invalid byte sequences in a string. Two text encoding functions, utf8_encode and utf8_decode, are included because in PHP 7.2 they were moved into the core from an optional extension. On Windows specifically, a function for controlling terminal color support is also provided. The package also defines several PHP 7.2 numeric constants related to floating-point precision and the name of the operating system family. This is part of the larger Symfony project, which is a set of PHP components widely used to build web applications. The polyfill is typically pulled in automatically as a dependency of other Symfony packages or third-party libraries that want to support a range of PHP versions without writing version-check code themselves. It is released under the MIT license. The README is short by design because the package itself is narrow in scope.

Copy-paste prompts

Prompt 1
My PHP 7.0 project uses spl_object_id which only exists in PHP 7.2. Show me how to add symfony/polyfill-php72 via Composer and confirm the function is available without writing any version-check code.
Prompt 2
Explain what functions symfony/polyfill-php72 provides and give a code example showing how mb_ord and mb_chr work to convert between a character and its numeric code point.
Prompt 3
I'm upgrading a legacy PHP application from 7.0 to 7.2 in stages. Show me how to use symfony/polyfill-php72 as a bridge so I can write PHP 7.2-style code now while the server is still on 7.0.
Open on GitHub → Explain another repo

← symfony on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.