Bug #81442 [Opn->Nab]: Deprecation warning(?) does not trigger error handler
| From: | nikic@php.net | Date: | Wed, 15 Sep 2021 19:16:31 +0000 |
| Subject: | Bug #81442 [Opn->Nab]: Deprecation warning(?) does not trigger error handler | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236631@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
Updated by: nikic@php.net
Reported by: rkaiser at gmail dot com
Summary: Deprecation warning(?) does not trigger error
handler
-Status: Open
+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:
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.
Previous Comments:
------------------------------------------------------------------------
[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