PHP core functions that throw exceptions instead of returning false
open sourceMITfree
Safe PHP (thecodingmachine/safe) redeclares PHP's core functions in the Safe namespace so they behave exactly as the originals but throw exceptions on error instead of returning false, so a failed file_get_contents or json_decode can't slip through unchecked. Import the function from Safe and the rest of the code stays the same; a PHPStan rule (thecodingmachine/phpstan-safe-rule) flags calls to the unsafe originals.
Problems it solves
- make file_get_contents throw an exception instead of returning false
- stop silent false returns from PHP built-in functions
- enforce exception-based error handling in a PHP codebase
Features
- core PHP functions that throw exceptions
- same names in the Safe namespace
- PHPStan rule to catch unsafe calls
Alternatives
The same job
These do what Safe PHP does.
- Collision Readable error reports for PHP command-line apps
