php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rkaiser at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-15 18:50 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-15 19:16 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-09-15 19:16 UTC] 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 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 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.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun May 22 21:05:44 2022 UTC