Bug #73665 [Com]: set_error_handler cant't listen E_Deprecated when opcache loaded

From: Date: Fri, 13 Jan 2023 13:44:31 +0000
Subject: Bug #73665 [Com]: set_error_handler cant't listen E_Deprecated when opcache loaded
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243439@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73665&edit=1 ID: 73665 Comment by: jochem dot blok at fasterforward dot nl Reported by: lcx165 at gmail dot com Summary: set_error_handler cant't listen E_Deprecated when opcache loaded Status: Verified Type: Bug Package: opcache Operating System: Linux 64bit NTS PHP Version: 7.0.13 Block user comment: N Private report: N New Comment: Tested this in php 8.2.1 with the code below: jochem.php ----------- error_reporting(E_ALL); 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"; var_dump($error); echo "\n--------------- EO: SHUTDOWN ---------------------\n\n"; } } register_shutdown_function('shutdown'); function myErrorHandler($errno, $errstr, $errfile, $errline) { echo "\n\n--------------- ERROR ---------------------\n\n"; var_dump(error_reporting()); echo "\n" . 'errno = '; print_r($errno); echo "\n" . 'errstr = '; print_r($errstr); echo "\n" . 'errfile = '; print_r($errfile); echo "\n" . 'errline = '; print_r($errline); echo "\n--------------- EO: ERROR ---------------------\n\n"; // die(); return true; // return false; } set_error_handler("myErrorHandler"); 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"; } set_exception_handler('exception_handler'); require 'jochem2.php'; echo "\nEOF"; ----------- jochem2.php ----------- <?php class A { final private function iets() { } } $a2 =new A(); ----------- Previous Comments: ------------------------------------------------------------------------ [2021-09-15 21:03:27] 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. https://bugs.php.net/bug.php?id=81442 has an example using a different deprecation case. ------------------------------------------------------------------------ [2020-09-07 07:40:43] nikic@php.net Related To: Bug #80058 ------------------------------------------------------------------------ [2020-01-30 10:23:51] nikic@php.net @rasmus at mindplay dot dk: Only triggers deprecation since 7.4. Was blocked on https://wiki.php.net/rfc/tostring_exceptions. ------------------------------------------------------------------------ [2020-01-30 10:20:24] 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: https://3v4l.org/SsL0q 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? ------------------------------------------------------------------------ [2019-08-27 21:55:57] 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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=73665 -- Edit this bug report at https://bugs.php.net/bug.php?id=73665&edit=1

« previous php.bugs (#243439) next »