Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error supression is not detected correctly on PHP8+ #808

Open
calvinalkan opened this issue Sep 1, 2023 · 1 comment
Open

error supression is not detected correctly on PHP8+ #808

calvinalkan opened this issue Sep 1, 2023 · 1 comment

Comments

@calvinalkan
Copy link

This condition will never return true,

if ( 0 === error_reporting() && 0 !== $this->error_reporting ) {
	// This is most likely an @-suppressed error
	$error_group = 'suppressed';
}

On PHP8+, error_reporting never return 0.

Warning

Prior to PHP 8.0.0, the error_reporting() called inside the custom error handler always returned 0 if the error was suppressed by the @ operator. As of PHP 8.0.0, it returns the value E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE.

See: https://www.php.net/manual/en/language.operators.errorcontrol.php

This causes suppressed errors to be reported as actual errors.

Instead, something like this should be used:

    private function nonSilentErrorTypes(): int
    {
        return E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
    }

    private function isErrorSuppressed(): bool
    {
        $current_level = error_reporting();

        if (PHP_MAJOR_VERSION > 7) {
            // https://www.php.net/manual/en/language.operators.errorcontrol.php
            return $current_level === $this->nonSilentErrorTypes();
        }

        return 0 === $current_level;
    }
@johnbillion
Copy link
Owner

Thanks, this was reported in the support forums too. See #801. I'll close that one off as this ticket has more info.

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

No branches or pull requests

2 participants