A lightweight compatibility layer that brings PHP 8.0+ string and array functions to PHP 7.1+ applications.
- 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
Install via Composer:
composer require napryc/php8-compat
mb_str_pad()
- Pad a string to a certain length with another stringstr_contains()
- Determine if a string contains a given substringstr_starts_with()
- Check if a string starts with a given substringstr_ends_with()
- Check if a string ends with a given substringstr_increment()
- Increment a stringstr_decrement()
- Decrement a stringmb_trim()
- Strip whitespace or other characters from both sidesmb_ltrim()
- Strip whitespace or other characters from the left sidemb_rtrim()
- Strip whitespace or other characters from the right sidemb_ucfirst()
- Make a string's first character uppercasemb_lcfirst()
- Make a string's first character lowercase
array_is_list()
- Determine if an array is a list
fdiv()
- Divide two numbers with proper handling of division by zero
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"
// Array checking
$isList = PHP8Compat::array_is_list([1, 2, 3]); // true
$isList = PHP8Compat::array_is_list(['a' => 1]); // false
// Safe division
$result = PHP8Compat::fdiv(10, 0); // INF
- PHP 7.1 or higher
- ext-mbstring extension
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.