MUtils is a collection of useful functions and to provide some PHP 8.0+ features for older PHP versions.
If you use the functions from this Library, it checks if you are using PHP 8.0+ and use then the internal functions (pass-through).
- Sorting Functions (They have a slow performance if it's not pass-through! - https://wiki.php.net/rfc/stable_sorting)
- asort, arsort, ksort, krsort, natcasesort, natsort, rsort, sort, uasort, uksort, usort
- String Functions
- str_contains, str_ends_with, str_starts_with
- Array Functions - Functions to optimize working with arrays
- array_compare_flags, array_move_element, array_group_by, array_prefix_add, array_prefix_remove
- Bitwise Functions - Some useful functions to work with sets of bits.
- bit_set, bit_isset, bit_unset
- Reflection Functions - Useful functions to get ReflectionClass, ReflectionMethod and ReflectionProperty on inheritance
- get_reflection_class, get_reflection_method, get_reflection_property
<?php
$array = [128, 2, 16, 64, 8, 1, 32];
// or MUtils\Arrays::userAssociativeSort()
MUtils\Arrays\uasort($array, static function ($left, $right) {
return $left <=> $right;
})
<?php
// or MUtils\Strings::startsWith()
if (MUtils\Strings\str_starts_with('Some Text', 'Some')) {
// ...
}
<?php
// or MUtils\Bits::isset()
if (MUtils\Bits\bit_isset(12, 4)) {
// ...
}
<?php
// or MUtils\Objects::getReflectionMethod()
$instance = new Something();
$method = MUtils\Objects\get_reflection_method($instance, 'foo');
if ($method) {
$method->invoke($instance, 'arg');
// ...
}