PHPackages                             chillerlan/php-standard-utilities - 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. chillerlan/php-standard-utilities

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

chillerlan/php-standard-utilities
=================================

A collection of reusable multi-purpose functions for PHP libraries.

1.0.3(1mo ago)08.3k↓26.8%2MITPHPPHP ^8.1CI failing

Since Nov 12Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/chillerlan/php-standard-utilities)[ Packagist](https://packagist.org/packages/chillerlan/php-standard-utilities)[ Docs](https://github.com/chillerlan/php-standard-utilities)[ Fund](https://ko-fi.com/codemasher)[ RSS](/packages/chillerlan-php-standard-utilities/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (13)Versions (6)Used By (2)

chillerlan/php-standard-utilities
=================================

[](#chillerlanphp-standard-utilities)

A collection of reusable multi-purpose functions for PHP libraries.

[![PHP Version Support](https://camo.githubusercontent.com/e75e9b3428073d17c341b77eb535cad52e7ffe2d4555b9ff9cfb8d545263244a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c69746965733f6c6f676f3d70687026636f6c6f723d383839324246266c6f676f436f6c6f723d666666)](https://www.php.net/supported-versions.php)[![Packagist version](https://camo.githubusercontent.com/e08769c09f87b862a1ce6a5b568975cc6b33ed92c002ff168d40dbf84f4f346f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c69746965732e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666)](https://packagist.org/packages/chillerlan/php-standard-utilities)[![License](https://camo.githubusercontent.com/2429c3557c6b2f84c775c409969e9217cc4cd810ad0e5bddb893988892d73234/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c6974696573)](https://github.com/chillerlan/php-standard-utilities/blob/main/LICENSE)[![Continuous Integration](https://camo.githubusercontent.com/0a0166ee7575e56e60d3672aefea2b49a8f5b70cb50d1346dbac3d7819d72567/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c69746965732f63692e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562266c6f676f436f6c6f723d666666)](https://github.com/chillerlan/php-standard-utilities/actions/workflows/ci.yml?query=branch%3Amain)[![CodeCov](https://camo.githubusercontent.com/733f9d7e76101ae0342dac8b2818e1a6851d34ddcfae6f73b3185dd6243da9e5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c69746965732e7376673f6c6f676f3d636f6465636f76266c6f676f436f6c6f723d666666)](https://codecov.io/github/chillerlan/php-standard-utilities)[![Packagist downloads](https://camo.githubusercontent.com/707db2d558abdaabde632f20fcac59ba556e5f58c809ac1b777eae6d367aab3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696c6c65726c616e2f7068702d7374616e646172642d7574696c69746965732e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666)](https://packagist.org/packages/chillerlan/php-standard-utilities/stats)

Overview
--------

[](#overview)

### Features

[](#features)

This library features some common functions to reduce overall duplication and avoid certain ugly workarounds (looking at you, phpstan...).

### Requirements

[](#requirements)

- PHP 8.4+
    - extensions: `json`, `mbstring`, `sodium`

API
---

[](#api)

### `Arr`

[](#arr)

(we can't use `array` as class name because reasons)

methoddescription`Arr::first(array $array):mixed`Returns the first element of an array, `null` if the given array is empty.`Arr::last(array $array):mixed`Returns the last element of an array, `null` if the given array is empty.`Arr::random(array $array):mixed`Returns a random element of an array, `null` if the given array is empty.### `Crypto`

[](#crypto)

methoddescription`Crypto::sha256(string $data, bool $binary = false):string`Generates an SHA-256 hash for the given value`Crypto::sha512(string $data, bool $binary = false):string`Generates an SHA-512 hash for the given value`Crypto::randomString(int $length, string $keyspace = Crypto::ASCII_COMMON_PW):string`Generates a secure random string of the given `$length`, using the characters (8-bit byte) in the given `$keyspace`.`Crypto::createEncryptionKey():string`Creates a new cryptographically secure random encryption key for use with `encrypt()` and `decrypt()` (returned in hexadecimal format)`Crypto::encrypt(string $data, string $keyHex, int $format = Crypto::ENCRYPT_FORMAT_HEX):string`Encrypts the given `$data` with `$key`, formats the output according to `$format` \[binary, base64, hex\]`Crypto::decrypt(string $encrypted, string $keyHex, int $format = Crypto::ENCRYPT_FORMAT_HEX):string`Decrypts the given `$encrypted` data with `$key` from input formatted according to `$format` \[binary, base64, hex\]The `Crypto` class defines the following public constants:

pre-defined character maps for use with `Crypto::randomString()` as `$keyspace`:

- `NUMERIC`: numbers `0-9`
- `ASCII_LOWER`: ASCII `a-z`
- `ASCII_UPPER`: ASCII `A-Z`
- `ASCII_SYMBOL`: ASCII printable symbols `!"#$%&\'()*+,-./:;?@[\]^_`{|}~`
- `HEXADECIMAL`: numbers `0-9` + ASCII `a-f`
- `ASCII_ALPHANUM`: numbers `0-9` + ASCII `a-z` + `A-Z`
- `ASCII_PRINTABLE`: numbers `0-9` + ASCII `a-z` + `A-Z` + printable symbols
- `ASCII_COMMON_PW`: ASCII alphanum + most of ASCII printable symbols `!#$%&()*+,-./:;?@[]~_|` (minus a few troublemakers)

output and input `$format` for the functions `Crypto::encrypt()` and `Crypto::decrypt()`, respectively:

- `ENCRYPT_FORMAT_BINARY`: raw binary
- `ENCRYPT_FORMAT_BASE64`: mime base64
- `ENCRYPT_FORMAT_HEX`: hexadecimal

### `Directory`

[](#directory)

methoddescription`Directory::exists(string $dir):bool`Checks whether a directory exists`Directory::isReadable(string $dir):bool`Checks whether the given directory is readable`Directory::isWritable(string $dir):bool`Checks whether the given directory is writable`Directory::create(string $dir, int $permissions = 0o777, bool $recursive = true):string`Creates a directory`Directory::remove(string $dir):bool`Removes a directory`Directory::relativePath(string $path, string $from, string $separator = DIRECTORY_SEPARATOR):string`Returns the relative path from the given directory### `File`

[](#file)

methoddescription`File::exists(string $file):bool`Checks whether a file exists`File::isReadable(string $file):bool`Checks whether the given file is readable`File::isWritable(string $file):bool`Checks whether the given file is writable`File::realpath(string $path):string`Returns the absolute real path to the given file or directory`File::delete(string $file):bool`Deletes a file`File::load(string $file, int $offset = 0, int|null $length = null):string`reads the given file into a string`File::save(string $file, string $data):int`saves the given data string to the given file path`File::loadJSON(string $file, bool $associative = false, int $flags = 0):mixed`load a JSON string from file into an array or object (convenience)`File::saveJSON(string $file, mixed $data, int $flags = Str::JSON_ENCODE_FLAGS_DEFAULT):int`save to a JSON file (convenience)### `Str`

[](#str)

(see `Arr`)

methoddescription`Str::filter(array $mixed):array`Filters an array and removes all elements that are not strings. Array keys are *not* retained`Str::toUpper(array $strings):array`Converts the strings in an array to uppercase`Str::toLower(array $strings):array`Converts the strings in an array to lowercase`Str::startsWith(string $haystack, array $needles, bool $ignoreCase = false):bool`Checks whether the given string starts with *any* of the given array of needles`Str::containsAll(string $haystack, array $needles, bool $ignoreCase = false):bool`Checks whether the given string (haystack) contains *all* of the given array of needles`Str::containsAny(string $haystack, array $needles, bool $ignoreCase = false):bool`Checks whether the given string (haystack) contains *any* of the given array of needles`Str::jsonDecode(string $json, bool $associative = false, int $flags = 0):mixed`Decodes a JSON string`Str::jsonEncode(mixed $data, int $flags = self::JSON_ENCODE_FLAGS_DEFAULT):string`Encodes a value into a JSON representation`Str::base64encode(string $string, int $variant = SODIUM_BASE64_VARIANT_ORIGINAL):string`Encodes a binary string to base64 (timing-safe)`Str::base64decode(string $base64, int $variant = SODIUM_BASE64_VARIANT_ORIGINAL, string $ignore = ''):string`Decodes a base64 string into binary (timing-safe)Disclaimer
----------

[](#disclaimer)

Use at your own risk!

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

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 ~123 days

Total

5

Last Release

58d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ada3d048807a11e536645fb87da881170b18f34c0c61fa09e34807c5d79e0b89?d=identicon)[codemasher](/maintainers/codemasher)

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (26 commits)")

---

Tags

functionsutilities

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chillerlan-php-standard-utilities/health.svg)

```
[![Health](https://phpackages.com/badges/chillerlan-php-standard-utilities/health.svg)](https://phpackages.com/packages/chillerlan-php-standard-utilities)
```

###  Alternatives

[ilya/belt

A handful of tools for PHP developers.

71020.8k1](/packages/ilya-belt)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[lodash-php/lodash-php

A port of Lodash to PHP

527719.0k5](/packages/lodash-php-lodash-php)[maciejczyzewski/bottomline

A full-on PHP manipulation utility belt that provides support for working with arrays, objects, and iterables; a lodash or underscore equivalent for PHP.

477631.4k10](/packages/maciejczyzewski-bottomline)[kartik-v/yii2-helpers

A collection of useful helper functions for Yii Framework 2.0

883.0M29](/packages/kartik-v-yii2-helpers)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)

PHPackages © 2026

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