Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.

PHP Error Handling

Modern PHP error and exception handling standards.

majiayu000 7d692ac 2 files · 1.6 KB Updated 567 repo stars

File contents

PHP Error Handling

Priority: P0 (CRITICAL)

Structure

src/
└── Exceptions/
    ├── {Domain}Exception.php
    └── Handler.php

Implementation Guidelines

  • Exception-Driven: Prefer throwing exceptions over returning false.
  • Throwable Interface: Catch Throwable for both Errors and Exceptions.
  • Custom Exceptions: Extend RuntimeException for domain-specific errors.
  • Multi-catch: Use catch (TypeA | TypeB $e) for identical handling.
  • Finally Cleanup: Use finally to ensure resource release.
  • Global Handling: Set set_exception_handler in entry points.
  • PSR-3 Logging: Log critical faults using standard loggers.

Anti-Patterns

  • Error Suppression: No @: Avoid suppressing errors with @.
  • Silent Catch: No Empty Catches: Log or handle all caught exceptions.
  • Logic Flow: No Flow Control: Don't use exceptions for expected logic.
  • Panic Display: No display_errors: Log to file, never to production screen.

References

  • Exception & Logging Patterns

majiayu000/claude-skill-registry-data/tree/main/development/error-handling-fierzone-agent-skills-standar commit 7d692ac4f9

Frequently asked questions

npx skillmds add majiayu000/php-error-handling