GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Downloads
  • Documentation
  • Get Involved
  • Help
  • Getting Started
  • Introduction
  • A simple tutorial
  • Language Reference
  • Basic syntax
  • Types
  • Variables
  • Constants
  • Expressions
  • Operators

This view

  • Original page
  • New address

GeezerVison is showing www.php.net — PHP: get_error_handler - Manual

PHP 8.6.0 RC5 available for testing
    get_exception_handler »
    « error_reporting
    • Preface
    • Function Reference
    • Affecting PHP's Behaviour
    • Error Handling
    • Error Handling Functions

    get_error_handler

    (PHP 8 >= 8.5.0)

    get_error_handler — Gets the user-defined error handler function

    Description

    function get_error_handler(): ?callable

    Returns the current error handler function, if any.

    Parameters

    This function has no parameters.

    Return Values

    Returns the currently defined error handler (if any). If the built-in error handler is used null is returned.

    The returned handler is the exact callable value that was passed to set_error_handler() to define it.

    Examples

    Example #1 get_error_handler() example

    <?php
    
    $handler = function (int $errno, string $errstr, ?string $errfile, ?int $errline) {
         echo "Error: " . $errstr . "\n";
    };
    
    var_dump(get_error_handler()); // NULL
    
    set_error_handler($handler);
    
    var_dump(get_error_handler() === $handler); // bool(true)
    
    ?>

    Notes

    Tip

    Prior to PHP 8.5.0, this functionality can be provided by the following polyfill:

    <?php
    if (!function_exists('get_error_handler')) {
        function noop_error_handler() {
        }
        function get_error_handler(): ?callable {
            $handler = set_error_handler('noop_error_handler');
            restore_error_handler();
            return $handler;
        }
    }
    ?>

    See Also

    • error_reporting() - Sets which PHP errors are reported
    • set_error_handler() - Sets a user-defined error handler function
    • restore_error_handler() - Restores the previous error handler function
    • trigger_error() - Generates a user-level error/warning/notice message
    • error level constants

    Found A Problem?

    Learn How To Improve This Page • Submit a Pull Request • Report a Bug
    +add a note

    User Contributed Notes

    There are no user contributed notes for this page.
    • Error Handling Functions
      • debug_​backtrace
      • debug_​print_​backtrace
      • error_​clear_​last
      • error_​get_​last
      • error_​log
      • error_​reporting
      • get_​error_​handler
      • get_​exception_​handler
      • restore_​error_​handler
      • restore_​exception_​handler
      • set_​error_​handler
      • set_​exception_​handler
      • trigger_​error
      • user_​error
    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.