On Sun, Dec 14, 2025, 10:34 AM Yousha Aleayoub <[email protected]> wrote:
> Hello, > > I’m submitting for discussion and vote a new PSR proposal to address a > long-standing gap in PHP’s *error-handling* ecosystem: > > Standard Interfaces for Recoverable Errors and Operation Results > *(Working title: PSR-XX Error and Result Interfaces)* > > *The problem* > PHP *forces *developers to choose between two flawed patterns for > non-exceptional failures: > > > - Throwing exceptions for expected outcomes (like validation errors, > cache misses) -> breaks control flow, hurts performance, and conflates > recoverable vs. unrecoverable errors. > - Returning ambiguous values (null, false, ['error' => ...]) → > destroys type safety and forces brittle checks across the call stack. > > Frameworks and libraries reinvent this wheel constantly: > > - Laravel’s ValidationException > - Symfony’s ConstraintViolationList > - Guzzle’s TransferException + status codes > - Custom Result<bool, string> classes in libraries... > > There is no interoperable, type-safe way to return structured, recoverable > errors. > > *The Solution* > This PSR will propose three minimal, zero-dependency interfaces: > > > 1. ResultInterface: a sealed union for success/failure states > 2. SuccessInterface: wraps a successful value > 3. FailureInterface: wraps structured error data (code, message, > context) and optionally a Throwable > > *Key features* > > - No exceptions required for expected failures! > - Immutable, readonly objects > - Pattern-matchable via isSuccess()/isFailure() > - Composable with PSR-3 (logging), PSR-11 (containers), *and async > runtimes* > - Zero runtime overhead – pure interfaces, no DI or middleware > > Thanks for your time. > > -- > You received this message because you are subscribed to the Google Groups > "PHP Framework Interoperability Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion visit > https://groups.google.com/d/msgid/php-fig/ed4abd14-7f0c-4559-988c-8afd04538be3n%40googlegroups.com > <https://groups.google.com/d/msgid/php-fig/ed4abd14-7f0c-4559-988c-8afd04538be3n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > Thanks for putting this and the PR together. I definitely think this would be a good thing to have, but I agree with Larry that the lack of generics makes this challenging. The solution you provide in this thread is different than whats presented in https://github.com/php-fig/fig-standards/pull/1344 . Can you clarify what you intend to do to avoid the mixed typing for both success and failure? Are you thinking an implementor would provide a different result class for each possible result? Thanks, Korvin > -- You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/php-fig/CANeXGWUiCBtW5z0RMCaFr2y%3DYOgTH23knTWMBxgir215ZqisHg%40mail.gmail.com.
