
Unit
PHP Units & Dimensions Library
A lightweight, type-safe PHP library for working with quantities, units, and dimensional analysis. Inspired by scientific computing needs, this library lets you define units, register them globally, perform arithmetic with dimension checking, and convert across compatible units.
Features
Immutable objects
Dimensionally-aware arithmetic (
add, subtract, multiply, divide)Automatic conversion between compatible units (e.g., cm to m)
Support for compound units (e.g., m/s, kg⋅m²/s²)
Enum-powered unit naming (
Name enum)Custom unit registry
Installation
Basic Usage
output:
Arithmetic Support
All operations return new
Quantity objects with proper dimensions and units.Unit Registration
Define and register your own units:
Exception Handling
Operations on incompatible dimensions will throw an exception:
Running Tests
This project uses PHP-internal's built-in
run-tests.php format.Or
Each test follows
.phpt format and validates expected behavior.Project Structure
About
Built by Khaled Alam to bring better scientific and data modeling features to PHP developers.
0 likes · 7 views · Jul 14, 2025
Developed a PHP library for units and dimensions with dimensional analysis.