Bug #81442 [Com]: Deprecation warning(?) does not trigger error handler
| From: | rkaiser at gmail dot com | Date: | Wed, 15 Sep 2021 21:00:09 +0000 |
| Subject: | Bug #81442 [Com]: Deprecation warning(?) does not trigger error handler | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236632@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81442&edit=1
ID: 81442
Comment by: rkaiser at gmail dot com
Reported by: rkaiser at gmail dot com
Summary: Deprecation warning(?) does not trigger error
handler
Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: CentOS 7.7
PHP Version: 8.0.10
Block user comment: N
Private report: N
New Comment:
Ah, fair enough. If I include test() in a separate file it does hit the error handler.
That said, it still doesn't hit the handler (the first time) in that case if opcache is
enabled. From your comment in https://bugs.php.net/bug.php?id=80058 it sounds
like this is open bug https://bugs.php.net/bug.php?id=73665. I will add
a note there that it's still an issue in 8.0.10.
Previous Comments:
------------------------------------------------------------------------
[2021-09-15 19:16:31] nikic@php.net
An error handler cannot catch a *compile-time* deprecation warning in the same file. It will work
just fine for warnings in other files though.
------------------------------------------------------------------------
[2021-09-15 18:50:32] rkaiser at gmail dot com
Description:
------------
If you have a function with parameter with a default value preceding a required parameter
(https://www.php.net/manual/en/migration80.deprecated.php), you get a deprecation warning (or
notice? not clear which it is). However this warning doesn't get caught by
set_error_handler() for some reason.
I first noticed this while using opcache (see https://bugs.php.net/bug.php?id=73665) but then
noticed it repros even without opcache enabled.
Test script:
---------------
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
// This never hits
die('caught in error handler');
});
function test($a = 1, $b ) {
echo 'this executes';
}
// Displays "Deprecated: Required parameter $b follows optional parameter $a"
test(null, null);
Expected result:
----------------
I would expect the error handler to catch this warning.
Actual result:
--------------
Function executes and displays the warning.
If set_error_handler() is not supposed to catch this, is there another mechanism in PHP 8 to catch
this warning at runtime? It's often not practical to fix the references in 3rd party code that
hasn't been updated for PHP 8 yet.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81442&edit=1