# thecodingmachine/safe

All PHP functions, rewritten to throw exceptions instead of returning false

Repository: https://github.com/thecodingmachine/safe
Canonical: https://ross.abutalabs.com/products/safe
Language: PHP
License: MIT
License Family: permissive
Topics: php, functions, exceptions
Last push: 2026-08-17T23:43:41+00:00

## Health v2 (maintenance only)
Score: 89/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 98, release rhythm 71, longevity 100
- inputs: {"age_days": 2921, "days_push": 16, "days_rel": 199, "gap_med": 12, "n_releases_24m": 8}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2496, forks 169 (observed 2026-08-28T04:06:56.700002+00:00)

## What it is
Safe-PHP redeclares PHP core functions in a Safe namespace so they throw exceptions instead of returning false on error. It also provides Safe DateTime classes and a PHPStan rule to enforce usage of the safe variants.

## Use cases
- replace php functions that return false with exception-throwing versions
- avoid silently ignoring errors from file_get_contents or json_decode
- enforce safe function usage with phpstan
- write cleaner php error handling without manual false checks
- get exception-throwing datetime classes

## When to choose
- you want exceptions instead of false return values from PHP core functions
- you use PHPStan and want automated enforcement of safe function imports
- you are starting a new PHP project and want robust error handling by default

## When to avoid
- you cannot change function calls in a large legacy codebase
- you need minimal dependencies and prefer manual error checking
- your framework already wraps core functions with its own error handling

## Facets
- artifact type: library
- maturity: active
- function: error-handling, developer-tools
- domain: developer-tools, programming-languages
- platform: php
- tags: exceptions, php-core-functions, phpstan, static-analysis

## Member repositories
- thecodingmachine/safe (main) score 89

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:56.700002+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:27:12.429092+00:00, confidence not recorded.
  - readme: https://github.com/thecodingmachine/safe (fetched 2026-08-28T04:06:56.700002+00:00, sha 1abf27ccbb8e)
- Data as of 2026-08-30T08:39:29.467469+00:00.
