LogicException
PHPERRORCommonLogic

Logic error — represents a programming bug

Quick Answer

Throw subclasses of LogicException (InvalidArgumentException, BadMethodCallException, etc.) to signal programming mistakes.

What this means

Base SPL exception for errors that represent bugs in the program logic — conditions that should have been caught at development time. Use for precondition violations.

Why it happens
  1. 1Method called before required initialization
  2. 2Abstract method called incorrectly

Fix

Use specific LogicException subclass

Use specific LogicException subclass
class OrderProcessor {
    private bool $initialized = false;

    public function init(): void {
        $this->initialized = true;
    }

    public function process(Order $order): void {
        if (!$this->initialized) {
            throw new \LogicException("Call init() before process()");
        }
    }
}

Why this works

LogicExceptions signal bugs — do not catch and swallow them; let them surface to developers.

Code examples
Hierarchyphp
// LogicException hierarchy:
// LogicException
//   BadFunctionCallException
//     BadMethodCallException
//   DomainException
//   InvalidArgumentException
//   LengthException
//   OutOfRangeException

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PHP errors