error_reporting

error_reporting(?int $error_level = null): int

Sets which error levels are reported and returns the current level.

C C23

C23
#include <stdio.h>

#define REPORTING 1 /* 0=off, 1=error only, 2=include warnings */

#if REPORTING >= 2
#define report_warn(msg) puts(msg)
#else
#define report_warn(msg)
#endif
#define report_error(msg) puts(msg)

int main(void) {
    report_warn("warning: skipped");
    report_error("error: boom");
    return 0;
}
Output
error: boom

C++ C++26

C++26
#include <iostream>

#define REPORTING 1 /* 0=off, 1=error only, 2=include warnings */

#if REPORTING >= 2
#define report_warn(msg) std::cout << msg << "\n"
#else
#define report_warn(msg)
#endif
#define report_error(msg) std::cout << msg << "\n"

int main() {
    report_warn("warning: skipped");
    report_error("error: boom");
    return 0;
}
Output
error: boom

C# v11.0.100

v11.0.100
using System.Diagnostics;

var traceSwitch = new TraceSwitch("App", "App diagnostics") { Level = TraceLevel.Error };
Console.WriteLine(traceSwitch.Level);
Output
Error

Go v1.27.4

v1.27.4
package main

import "fmt"

const (
    levelWarn  = 2
    levelError = 1
)

var reporting = levelError

func report(level int, msg string) {
    if level <= reporting {
        fmt.Println(msg)
    }
}

func main() {
    report(levelWarn, "warning: deprecated")
    report(levelError, "error: boom")
}
Output
error: boom

Java v27.0.1

v27.0.1
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    public static void main(String[] args) {
        Logger log = Logger.getLogger("app");
        log.setLevel(Level.WARNING);
        System.out.println(log.getLevel());
    }
}
Output
WARNING

JavaScript v26.13.1

v26.13.1
const LEVELS = { off: 0, error: 1, warn: 2 };
let reporting = LEVELS.error;
function reportError(level, message) {
  if (LEVELS[level] <= reporting) console.log(level + ": " + message);
}
reportError("warn", "deprecated API");
reportError("error", "boom");
Output
error: boom

PHP v8.6.0

v8.6.0
error_reporting(E_ERROR | E_WARNING);
echo error_reporting();
Output
3

Python v3.15.2

v3.15.2
import logging

logging.getLogger().setLevel(logging.ERROR)
print(logging.getLogger().level)
Output
40

Rust v1.99.1

v1.99.1
#[derive(Clone, Copy, PartialEq, PartialOrd)]
enum Level {
    Off,
    Error,
    Warn,
}

fn report(level: Level, msg: &str, reporting: Level) {
    if level <= reporting {
        println!("{}", msg);
    }
}

fn main() {
    let reporting = Level::Error;
    report(Level::Warn, "warning: skipped", reporting);
    report(Level::Error, "error: boom", reporting);
}
Output
error: boom

TypeScript v26.13.1

v26.13.1
const LEVELS: Record<string, number> = { off: 0, error: 1, warn: 2 };
let reporting = LEVELS.error;
function reportError(level: string, message: string): void {
  if (LEVELS[level] <= reporting) console.log(level + ": " + message);
}
reportError("warn", "deprecated API");
reportError("error", "boom");
Output
error: boom

Language differences

C: trims diagnostics at compile time with preprocessor conditionals.

C++: same as C — preprocessor conditionals trim diagnostics.

C#: uses System.Diagnostics.TraceSwitch.

Go: no built-in global error level (the ecosystem convention is logging libraries or hand-rolled level switches — the example shows a minimal one).

Java: uses java.util.logging Level.

JavaScript: no built-in global error level (the ecosystem convention is logging libraries or hand-rolled level switches — the example shows a minimal one).

PHP: error_reporting uses a bitmask to control which error levels are reported at runtime; calling it without arguments queries the current value (E_ERROR|E_WARNING sums to 3 here); it is a global switch unique to scripting languages.

Python: conventionally uses logging levels (ERROR=40) or warnings filters.

Rust: no built-in global error level (the ecosystem convention is logging libraries or hand-rolled level switches — the example shows a minimal one).

TypeScript: same as JavaScript — no built-in global error level.