|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81442 Deprecation warning(?) does not trigger error handler
Submitted: 2021-09-15 18:50 UTC Modified: 2021-09-15 19:16 UTC
From: rkaiser at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 8.0.10 OS: CentOS 7.7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rkaiser at gmail dot com
New email:
PHP Version: OS:


 [2021-09-15 18:50 UTC] rkaiser at gmail dot com
If you have a function with parameter with a default value preceding a required parameter (, 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 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-15 19:16 UTC]
-Status: Open +Status: Not a bug
 [2021-09-15 19:16 UTC]
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 21:00 UTC] rkaiser at gmail dot com
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 it sounds like this is open bug  I will add a note there that it's still an issue in 8.0.10.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 19:01:31 2024 UTC