PHPackages                             napryc/php8-compat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. napryc/php8-compat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

napryc/php8-compat
==================

PHP 8 compatibility layer for PHP 7.1+ applications

v1.1.0(1y ago)02MITPHPPHP ^7.1 || ^8.0

Since Feb 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Napryc/PHP8Compat)[ Packagist](https://packagist.org/packages/napryc/php8-compat)[ RSS](/packages/napryc-php8-compat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PHP8 Compatibility Layer
========================

[](#php8-compatibility-layer)

A lightweight compatibility layer that brings PHP 8.0+ string and array functions to PHP 7.1+ applications.

Features
--------

[](#features)

- Multi-byte string functions support
- Array manipulation utilities
- Zero dependencies (except ext-mbstring)
- PHP 7.1+ compatible
- Automatic fallback to native PHP 8 functions when available

Installation
------------

[](#installation)

Install via Composer:

```
composer require napryc/php8-compat
```

Available Functions
-------------------

[](#available-functions)

### String Functions

[](#string-functions)

- `str_contains()` - Determine if a string contains a given substring
- `str_starts_with()` - Check if a string starts with a given substring
- `str_ends_with()` - Check if a string ends with a given substring
- `str_increment()` - Increment a string
- `str_decrement()` - Decrement a string
- `mb_str_pad()` - Pad a string to a certain length with another string
- `mb_trim()` - Strip whitespace or other characters from both sides
- `mb_ltrim()` - Strip whitespace or other characters from the left side
- `mb_rtrim()` - Strip whitespace or other characters from the right side
- `mb_ucfirst()` - Make a string's first character uppercase
- `mb_lcfirst()` - Make a string's first character lowercase

### Array Functions

[](#array-functions)

- `array_is_list()` - Determine if an array is a list
- `array_find()` - Find first element matching callback
- `array_find_key()` - Find first key matching callback
- `array_any()` - Check if any element matches callback
- `array_all()` - Check if all elements match callback

### Math Functions

[](#math-functions)

- `fdiv()` - Divide two numbers with proper handling of division by zero

### JSON Functions

[](#json-functions)

- `json_validate()` - Validate a JSON string

Usage
-----

[](#usage)

```
use Napryc\PHP8Compat\PHP8Compat;

// String manipulation
$padded = PHP8Compat::mb_str_pad("Hello", 10, "-"); // "Hello-----"
$contains = PHP8Compat::str_contains("Hello World", "World"); // true
$starts = PHP8Compat::str_starts_with("Hello World", "Hello"); // true
$ends = PHP8Compat::str_ends_with("Hello World", "World"); // true

// String increment/decrement
$next = PHP8Compat::str_increment("a"); // "b"
$prev = PHP8Compat::str_decrement("b"); // "a"

// Multi-byte string functions
$trimmed = PHP8Compat::mb_trim("  Hello  "); // "Hello"

// Array checking
$isList = PHP8Compat::array_is_list([1, 2, 3]); // true

// Array searching
$found = PHP8Compat::array_find([1, 2, 3], fn($x) => $x > 1); // 2
$foundKey = PHP8Compat::array_find_key([1, 2, 3], fn($x) => $x > 1); // 1
$hasAny = PHP8Compat::array_any([1, 2, 3], fn($x) => $x > 2); // true
$allMatch = PHP8Compat::array_all([1, 2, 3], fn($x) => $x > 0); // true

// Safe division
$result = PHP8Compat::fdiv(10, 0); // INF
```

Requirements
------------

[](#requirements)

- PHP 7.1 or higher
- ext-mbstring extension

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance43

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

3

Last Release

453d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/15dac85426defa067faf23f42275e9b9145b0d063f5f6af442a8af65272acf12?d=identicon)[napryc](/maintainers/napryc)

---

Top Contributors

[![Napryc](https://avatars.githubusercontent.com/u/18005617?v=4)](https://github.com/Napryc "Napryc (3 commits)")

---

Tags

compatibilitypolyfillphp8array-functionsstring functions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/napryc-php8-compat/health.svg)

```
[![Health](https://phpackages.com/badges/napryc-php8-compat/health.svg)](https://phpackages.com/packages/napryc-php8-compat)
```

###  Alternatives

[symfony/polyfill-mbstring

Symfony polyfill for the Mbstring extension

7.8k1.2B515](/packages/symfony-polyfill-mbstring)[symfony/polyfill-ctype

Symfony polyfill for ctype functions

4.0k982.0M125](/packages/symfony-polyfill-ctype)[symfony/polyfill-php72

Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions

4.7k674.7M31](/packages/symfony-polyfill-php72)[symfony/polyfill-intl-idn

Symfony polyfill for intl's idn\_to\_ascii and idn\_to\_utf8 functions

3.4k774.6M90](/packages/symfony-polyfill-intl-idn)[symfony/polyfill-intl-normalizer

Symfony polyfill for intl's Normalizer class and related functions

2.1k830.2M36](/packages/symfony-polyfill-intl-normalizer)[symfony/polyfill-php73

Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions

2.4k581.8M67](/packages/symfony-polyfill-php73)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
