Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Polyfill Php72 Laravel Package

symfony/polyfill-php72

Symfony Polyfill for PHP 7.2: backports core and mbstring functions like spl_object_id, stream_isatty, mb_ord/mb_chr/mb_scrub, utf8_encode/decode, plus PHP 7.2 constants (PHP_FLOAT_*, PHP_OS_FAMILY) and Windows VT100 support.

View on GitHub
Deep Wiki
Context7

Getting Started

This polyfill is typically used automatically by Laravel via Composer transitive dependencies—especially when targeting older PHP versions (e.g., 7.1) while using packages that rely on PHP 7.2+ features. To discover and use it directly:

  • Run composer show symfony/polyfill-php72 to inspect loaded version and autoloading.
  • Immediately usable in code without configuration: just call functions like mb_ord('é') or use PHP_OS_FAMILY anywhere in your app.
  • Common first use case: writing cross-version-safe string/encoding utilities or CLI tools needing stream_isatty() for terminal detection.

Implementation Patterns

  • Graceful feature detection: Wrap usage in function_exists() checks before calling polyfilled functions (e.g., if (!function_exists('mb_scrub')) { ... }), though the polyfill guarantees availability.
  • Laravel service providers or helpers: Use polyfilled functions in global helpers (e.g., app/helpers.php) for consistent behavior across legacy and modern PHP environments.
  • Console output styling: Leverage stream_isatty(STDOUT) in custom Artisan commands to conditionally enable colored output only on terminals.
  • Testing: In phpunit.xml, enforce minimal PHP version while testing fallback logic on polyfill-enabled environments (e.g., unit tests for Unicode-safe string processors).

Gotchas and Tips

  • No runtime autodiscovery warning: The polyfill is always loaded when installed—no manual require needed—but misconfigurations (e.g., OPcache clearing issues) may cause intermittent missing functions; run composer dump-autoload -o after updates.
  • Overlaps with polyfill-php73/74: Avoid installing multiple conflicting polyfills; prefer Symfony’s official polyfill chain (e.g., symfony/polyfill-php80 may supersede older ones). Check composer why symfony/polyfill-*.
  • Windows-specific quirks: sapi_windows_vt100_support() only works on Windows CLI; do not assume it exists on non-Windows OSes—even if the polyfill is installed.
  • utf8_encode/utf8_decode deprecation: These are deprecated in PHP 8.2+ and used only for legacy compatibility. Prefer mb_convert_encoding() in modern code, even with this polyfill active.
  • Extension precedence: If your system already has PHP 7.2+ (native functions exist), the polyfill does not override core functions—it only adds them where missing. Use function_exists() only to guard polyfill-specific behavior (e.g., fallback mocks in tests).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport