How should I design the exception hierarchy in a library so consumers can catch cleanly?
Define a root marker interface extending Throwable, mark recoverable errors with a thin RetryableException, and never throw a bare Exception.
Tag
Building applications with PHP: language features, versions and practices. Questions asked under this tag, each one answered directly.
7 answered questions carry this tag.
Define a root marker interface extending Throwable, mark recoverable errors with a thin RetryableException, and never throw a bare Exception.
Read attributes once per class into a cached mapping plan rather than per request, and compile to generated PHP only if the profile still shows reflection.
Stay in FPM and start with a Guzzle Pool pinned to 20-50 concurrency; move to AMPHP v3 only if the codebase grows async, Swoole only when re-architecting.
A readonly withX returns a new instance: new self with named arguments is portable, and clone($this, [...]) fits PHP 8.5 when validation is simple.
Integer cents in the DB, an immutable Money on the model: put the mapping in one CastsAttributes class and keep currency as a second column there.
Default to list<Order> docblocks with strict PHPStan in CI; add one generic Collection<T> for behavior, a concrete class only at a trust boundary.
Add a backed enum on the same integer values, use tryFrom() at the boundaries, and keep the old constants as deprecated aliases while you move call sites.