Skip to content

Migrate the error handling for the @ operator to php 8 state - #1141

Merged
ste93cry merged 2 commits into
getsentry:php8-supportfrom
chris-doehring:feature/php8-error_reporting_migration
Nov 27, 2020
Merged

ste93cry merged 2 commits into
getsentry:php8-supportfrom
chris-doehring:feature/php8-error_reporting_migration

Conversation

@chris-doehring

@chris-doehring chris-doehring commented Nov 27, 2020 •

Copy link
Copy Markdown

While trying to execute the unit tests of the latest state of the php8-support branch locally, I was able to find the reason why the error_handler_respects_error_reporting.phpt test keeps failing. The reason is mentioned in the official php 8 migration guide:

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers that expect error_reporting to be 0 when @ is used, should be adjusted to use a mask check instead:

<?php
// Replace
function my_error_handler($err_no, $err_msg, $filename, $linenum) {
    if (error_reporting() == 0) {
        return; // Silenced
    }
    // ...
}

// With
function my_error_handler($err_no, $err_msg, $filename, $linenum) {
    if (!(error_reporting() & $err_no)) {
        return; // Silenced
    }
    // ...
}
?>

You will see that the error_reporting under php 8 no longer returns 0 (none) within a custom error handler: https://3v4l.org/qZ1OG

After this change, my local tests run successful under php 7.2 - 8.0. This does not fix the Segmentation faults or the other remaining CI issues.

@chris-doehring chris-doehring changed the title Migrate the error handling for the @ operator to the latest php 8 change Migrate the error handling for the @ operator to php 8 state Nov 27, 2020
@chris-doehring chris-doehring mentioned this pull request Nov 27, 2020

@ste93cry ste93cry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a CHANGELOG entry?

Comment thread src/ErrorHandler.php Outdated

@ste93cry ste93cry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your help, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants