PHPUtil: PHP Helper Library (doganoo/php-util)

PHPUtil is a small open-source PHP library of helper classes I kept copying from project to project: comparing floats, getting an object's class name, validating integers, handling strings, sessions, files and a few other things. At some point I got tired of copy and paste and put them into one library. It is MIT-licensed and available on GitHub and Packagist as doganoo/php-util.
Facts as of November 2026 (from the repository and Packagist): latest tagged version 0.5.0 (September 2021), about 9,100 installs on Packagist, one runtime dependency on my data structure library doganoo/php-algorithms.
Installation
composer require doganoo/php-util
The library needs the PHP extensions fileinfo, iconv, mbstring, json and pdo. Classes are autoloaded under the namespace doganoo\PHPUtil\.
Supported PHP versions
composer.json does not declare a PHP version constraint. The library was written for PHP 7 (the repository is tagged php7), and its test suite uses PHPUnit 9. I do not state support for specific PHP 8 versions here.
Examples
The examples below use methods as they are in the current source code on GitHub.
Comparing floats
Floats should not be compared with ==, as the PHP manual warns. NumberUtil::compareFloat() treats two floats as equal when their difference is below 0.00001; floatGreaterThan() rounds both values to 10 decimals before comparing:
use doganoo\PHPUtil\Util\NumberUtil;
var_dump(0.1 + 0.2 == 0.3); // bool(false)
var_dump(NumberUtil::compareFloat(0.1 + 0.2, 0.3)); // bool(true)
var_dump(NumberUtil::floatGreaterThan(0.3, 0.1 + 0.2)); // bool(false)
var_dump(NumberUtil::floatGreaterThan(0.3, 0.1 + 0.2, true)); // bool(true), greater than or equal
Validating integers
intval() silently converts bad input: intval('42abc') is 42, intval('abc') is 0. NumberUtil::isInteger() uses filter_var() with FILTER_VALIDATE_INT instead, and stripNonInteger() keeps only the valid integers of an array:
use doganoo\PHPUtil\Util\NumberUtil;
NumberUtil::isInteger('42'); // true
NumberUtil::isInteger('42abc'); // false
NumberUtil::stripNonInteger(['1', 'two', '3', '4.5']); // [1, 3]
Class names and parent classes
ClassUtil wraps a few reflection calls. getClassName() returns the fully qualified class name of an object (or null for invalid input), getAllParentClasses() walks up the inheritance chain and returns the parents as an ArrayList from PHPAlgorithms:
use doganoo\PHPUtil\Util\ClassUtil;
$name = ClassUtil::getClassName(new \ArrayObject()); // 'ArrayObject'
$parents = ClassUtil::getAllParentClasses(new \LogicException(), false);
// ArrayList containing 'Exception' (LogicException extends Exception)
What else is in the library
The src/ directory currently contains, among others: Util (array, class, date/time, HTML, number and string helpers), HTTP (status codes, header builder, session, URL generator), FileSystem (directory and file handler), Storage (a PDO connector), Mail\Validator, Crypto\Base64, a small DI\Container and a class autoloader. The source on GitHub is the reference; the README itself is short.
Contributing
Missing something or found a bug? Open an issue or a pull request on GitHub.