Content · Programming · PHP

PHP error_reporting() Function: Usage and Examples

Learn how PHP error_reporting works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Gets or sets the current PHP error reporting level.

What Is error_reporting() in PHP?

Gets or sets the current PHP error reporting level.

Its syntax is:

error_reporting(?int $error_level = null): int

Parameters:

  • $error_level — Accepted as ?int; optional default null.

Return type: int. Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo error_reporting();

Output:

22527

Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Example 2: A Different Input

<?php

$previousLevel = error_reporting(E_ALL); error_reporting($previousLevel);

Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Practical Example: Applying It in a Program

<?php

$previousLevel = error_reporting(); error_reporting(E_ALL); echo "All errors enabled during task"; error_reporting($previousLevel);

Output:

All errors enabled during task

Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Important Behavior and Edge Cases

  • Key behavior: Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
error_reporting()Gets or sets the current PHP error reporting level.
ini_set()ini_set() changes a configurable PHP setting; error_reporting() gets or sets an error-reporting bitmask.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Error reporting is not the same as displaying errors to end usersError reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Key Takeaways

  • Gets or sets the current PHP error reporting level.
  • Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.
  • Core PHP.

Summary: Error reporting is not the same as displaying errors to end users. Avoid exposing warnings in production.

Share this resourceSend this page to someone who may find it useful.