# Safe PHP

> PHP core functions that throw exceptions instead of returning false

Source: https://talira.ai/catalog/safe-php-6fvvejcm
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / error handling](https://talira.ai/categories/libraries/error-handling), [languages / php](https://talira.ai/categories/languages/php)
- Licence: MIT[^1]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Backed by: [TheCodingMachine](https://talira.ai/orgs/thecodingmachine.md)

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](https://talira.ai/catalog/phpstan-5dffx9mn.md) rule (thecodingmachine/phpstan-safe-rule) flags calls to the unsafe originals.

## Links

- GitHub: https://github.com/thecodingmachine/safe

## 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

## Trust

Overall: 0.55 out of 1.
Signals: maintenance 0.71, adoption 0.68, momentum 0.43, community 0.74, backing 0.30, extensibility 0.00.

- last commit 3 days ago
- 17 commits in the last 90 days
- latest release v3.4.0 9 months ago
- 2.5k GitHub stars
- 68 contributors
- accepts sponsorship (Github, Github, Github)
- backed by TheCodingMachine

## Related

- Works with [PHPStan](https://talira.ai/catalog/phpstan-5dffx9mn.md)

## Alternatives

- [Collision](https://talira.ai/catalog/collision-z8qf4pds.md): Readable error reports for PHP command-line apps

## Sources

[^1]: https://github.com/thecodingmachine/safe/blob/master/LICENSE (checked 29 Nov 2026)
