|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73665 set_error_handler cant't listen E_Deprecated when opcache loaded
Submitted: 2016-12-06 09:36 UTC Modified: 2020-01-30 10:23 UTC
Avg. Score:4.0 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (16.7%)
From: lcx165 at gmail dot com Assigned:
Status: Verified Package: opcache
PHP Version: 7.0.13 OS: Linux 64bit NTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: lcx165 at gmail dot com
New email:
PHP Version: OS:


 [2016-12-06 09:36 UTC] lcx165 at gmail dot com
When loaded,use set_error_handler function listen all error.
When E_Deprecated happened, can't call error_handler function, use php system error display.

Test script:

class A {
    function a() {




set_error_handler(function($code, $msg, $file, $line) {
	echo  "[{$code}] {$msg}\r\n";

echo $a;

include 'a.php';

//run as cli: php error.php

Expected result:
[8] Undefined variable: a
PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in /root/a.php on line 3

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in /root/a.php on line 3

Actual result:
[8] Undefined variable: a
[8192] Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-19 10:41 UTC]
-Status: Open +Status: Verified
 [2017-02-19 10:42 UTC]
The expected and actual results above are swapped, but otherwise I can reproduce this at least for the first page request.
 [2019-08-27 21:55 UTC] dwilks at intacct dot com
I just ran into this as well and tracked it down to opcache running in Apache.  Yes, it only happens once, while the script is compiling the first time before being cached.

I assume it has something to do with opcache explicitly disabling the user_error_handler while compiling the script in opcache_compile_file.
 [2020-01-30 10:20 UTC] rasmus at mindplay dot dk
Has this been fixed in PHP 7.4?

I was expecting to catch deprecations in my test-suite, and as you can see here, a deprecation from PHP 7.1 was not caught in my 7.2 environment:

The deprecation can't be caught until 7.4, apparently.

Now, this could be either because the issue has been resolved - or just because this particular method was flagged in documentation as deprecated in 7.1 but wasn't actually triggering a deprecation notice until 7.4.

Any idea which it is?
 [2020-01-30 10:23 UTC]
@rasmus at mindplay dot dk: Only triggers deprecation since 7.4. Was blocked on
 [2021-09-15 21:03 UTC] rkaiser at gmail dot com
This is still an issue in PHP 8.0.10.  The first time a deprecation error is raised with opcache enabled, it doesn't trigger custom error handlers.  Subsequent loads of the script, however, do. has an example using a different deprecation case.
 [2023-01-13 13:44 UTC] jochem dot blok at fasterforward dot nl
Tested this in php 8.2.1 with the code below:

ini_set('display_errors', 1);
//header('Content-type: text/plain; charset=windows-1252');
header('Content-type: text/plain; charset=utf-8');

function shutdown()
    $error = error_get_last();
    if ($error) {
        echo "\n\n--------------- SHUTDOWN ---------------------\n\n";
        echo "\n--------------- EO: SHUTDOWN ---------------------\n\n";


function myErrorHandler($errno, $errstr, $errfile, $errline)
    echo "\n\n--------------- ERROR ---------------------\n\n";
    echo "\n" . 'errno = ';
    echo "\n" . 'errstr = ';
    echo "\n" . 'errfile = ';
    echo "\n" . 'errline = ';
    echo "\n--------------- EO: ERROR ---------------------\n\n";

//    die();
    return true;
//    return false;


function exception_handler($exception)
    echo "\n\n--------------- EXCEPTION ---------------------\n\n";
    echo "class: ", get_class($exception), "\n";
    echo "message: ", $exception->getMessage(), "\n";
    echo "regel: ", $exception->getLine(), "\n";
    echo "\n--------------- EO: EXCEPTION ---------------------\n\n";


require 'jochem2.php';

echo "\nEOF";


class A {
    final private function iets() {



$a2 =new A();

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun May 28 16:03:40 2023 UTC