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

Optimize error handling #144

Open
hannesbochmann opened this issue Mar 11, 2022 · 1 comment
Open

Optimize error handling #144

hannesbochmann opened this issue Mar 11, 2022 · 1 comment

Comments

@hannesbochmann
Copy link

Errors/warnings of functions which are suppressed with "@" (for example @array_keys_exist('test', new \stdClass()) in PHP 7.4) are not ignored by the error handling. In Respect\Rest\Request::prepareForErrorForwards() all errors are collected and later forwarded to the error route. Problem is that the information if a error/warning was suppressed with "@" isn't present in the error route anymore. It only can be checked in the PHP error handler callback through error_reporting() === 0. So this check needs to be done in Respect\Rest\Request::prepareForErrorForwards() before adding a error to the error side route. Method would look like this:

protected function prepareForErrorForwards()
    {
       foreach ($this->route->sideRoutes as $sideRoute) {
            if ($sideRoute instanceof Routes\Error) {
                return set_error_handler(
                    function () use ($sideRoute) {
                        // Don't do anything if error_reporting is disabled by an @ sign
                        if (error_reporting() !== 0) {
                            $sideRoute->errors[] = func_get_args();
                        }
                    }
                );
            }
        }
    }

I can provide a pull request, too.

@nickl-
Copy link
Member

nickl- commented Aug 3, 2022

You are welcome to roll a PR, please/thank you.

Remember to add a unit test.

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

No branches or pull requests

2 participants