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 Php80 Laravel Package

symfony/polyfill-php80

Backport of PHP 8.0 features for older PHP versions. Provides Stringable, fdiv, ValueError, UnhandledMatchError, get_debug_type, PhpToken, preg_last_error_msg, str_contains/starts_with/ends_with, get_resource_id, and FILTER_VALIDATE_BOOL.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require symfony/polyfill-php80

No configuration is required—it’s an autoloading-only polyfill. Once installed, PHP 8.0+ functions and classes become available on PHP 7.x (≥7.2) and early PHP 8.x versions lacking them. Start using features like str_contains(), fdiv(), or Stringable immediately in your codebase—they’ll work transparently regardless of PHP version.

Implementation Patterns

  • Write version-agnostic code: Use PHP 8.0+ APIs (e.g., str_starts_with($haystack, $needle)) even when targeting older PHP runtimes—polyfill ensures compatibility.
  • Testing & CI: Include polyfill-php80 in your CI pipeline to catch polyfill usage in tests, ensuring consistent behavior across PHP versions.
  • Library development: When building reusable packages, depend on this polyfill to safely use modern functions/classes without requiring high PHP versions. Auto-discoverable via composer require symfony/polyfill-php80 ^1.26.
  • Resource & token handling: Leverage get_resource_id(), PhpToken, and preg_last_error_msg() in low-level code (e.g., parsers, CLI tools) for cleaner diagnostics and resource management.

Gotchas and Tips

  • No runtime fallback for engine bugs: Polyfills only provide missing features—not fixes for PHP engine bugs (e.g., inconsistent fdiv() behavior on edge cases).
  • Class existence checks matter: If you conditionally use Stringable, always verify with interface_exists(Stringable::class) before referencing it (e.g., in type hints).
  • Autoload order: Since it’s a pure polyfill, conflicts are extremely rare, but avoid manually redefining polyfilled functions (e.g., custom str_contains()—could cause fatal errors).
  • Debugging tip: Run php -r 'var_dump(function_exists("str_contains"));' to verify polyfill loading on target servers.
  • Extend carefully: While the polyfill implements Stringable, PHP’s __toString() compatibility isn’t automatic—ensure classes meant to be Stringable actually declare the interface.
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