douglasgreen / utility
PHP utility project for exception classes and wrapper functions
v0.5.1
2024-08-04 21:19 UTC
Requires
- php: >=8.1
Requires (Dev)
- douglasgreen/config-setup: dev-main
- php-mock/php-mock: ^2.5
- phpstan/phpstan: ^1.11.9
- phpunit/phpunit: ^10.5.29
- rector/rector: ^1.2.2
- symplify/easy-coding-standard: ^12.3.4
README
A PHP utility project for exception classes and wrapper functions
Setup
Add the project with Composer.
composer require douglasgreen/utility
Benefits
PHP has an old core design dating back to its PHP 3 era. Examples include:
- Using functions instead of classes.
- Returning mixed types from functions.
- Returning false, null, or empty array to supress errors.
- Inconsistent function names and arguments.
- Returning arrays or resources from functions instead of objects.
- A mixture of mutable arguments and return values.
Even worse, the language introduced static typing and strict type checking tools.
- Returning false|string doesn't make sense and should return ?string.
- Type checkers force you to work harder to ignore errors using strict comparisons.
These utility classes wrap the PHP function calls and try to fix these problems.
Function signatures
The functions were renamed for clarity. Function argument order was preserved, except:
- Mutable arguments are now return values on getter functions.
- If a signal value is returned, return null rather than false.
- Arrays with multiple shapes and types were reduced to a single shape and type.