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

added version detection rather then suppressing obvious error #2438

Closed
wants to merge 2 commits into from
Closed

added version detection rather then suppressing obvious error #2438

wants to merge 2 commits into from

Conversation

brainfoolong
Copy link
Contributor

@brainfoolong brainfoolong commented Dec 7, 2021

This is:

- [x] a bugfix

Checklist:

Why this change is needed?

With PHP 8.1 ini_set('auto_detect_line_endings') is deprecated, as already correctly marked in the code.
But adding an explicit version detection instead of just letting the error silently happen, which fills internal error buffer and later still is returned by error_get_last() which many use to detect if any uncatchable php error happened.

In our case, we catch open errors with error_get_last() on shutdown and throw an exception when a error exist. This function also returns errors that are suppressed with @ and there is no way to detect if this error was suppressed.

With the version detection, we omit the error before it can happen, which is a nicer way instead of ducking.

With PHP 8.1 `ini_set('auto_detect_line_endings')` is deprecated.
Added a explicit version detection instead of just letting the error happen, which fills internal error buffer and later still is returned by `error_get_last()` which many use to detect if any uncatchable php error happened.
@brainfoolong
Copy link
Contributor Author

brainfoolong commented Dec 7, 2021

The failed test for PHP 8.1 does fail, as the version detection disable setAutoDetect.
In the official changelog there is already this entry, which already says that starting from PHP 8.1 the feature is not available anymore. The test should reflect this and should skip the test starting from 8.1. But i am not sure how you handle this in the repository. This should be fixed by someone that knows that.

  • PHP 8.1 will deprecate auto_detect_line_endings. As a result of this change, Csv Reader using PHP8.1+ will no longer be able to handle a Csv with Mac line endings.

@oleibman
Copy link
Collaborator

oleibman commented Dec 7, 2021

It sounds like you should be running a custom error handler which prevents error_get_last from seeing this message. Your solution has 2 problems. It takes code which works under 8.1 (the setting is deprecated, not eliminated), as you can see from the failing test, and makes it not work. Now, the documentation does say it won't work with 8.1+, so perhaps that is an out.

A bigger problem is that, although eliminating this particular message is straightforward, there are other places in the code which suppress messages. Those may not have an easy route to elimination, and, even if they have, I don't know that we want to get in the business of eliminating messages which we have already suppressed.

The following establishes an error_handler which would handle this situation:

set_error_handler(
    function (int $severity, string $message, string $file, int $line): bool
    {
        if (!(bool) (error_reporting() & $severity)) {
            return true;
        }
        return false;
    }
);

@brainfoolong
Copy link
Contributor Author

Ok i understand. I thought the cleaner way is version checking instead of suppression. Also because PhpSpreadsheet already have a lot of code that has version checks for deprecated features, insead of suppression, especially from PHP 7 to PHP 8.

Changing our error handler is not an easy thing to do and would only require doing this for this library. We generally not support error suppression here in our environment.

Maybe you may reconsider this, if not, no problem, than you can close this. I can deal with both variants.

@oleibman
Copy link
Collaborator

Closing for now. This will need a full-fledged solution when a version of PHP which officially stops supporting Mac line endings (8.2?) is available for testing.

@oleibman oleibman closed this Dec 12, 2021
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this pull request Feb 25, 2022
With the deprecation of `auto_detect_line_endings` in Php8.1, there have been some tickets (issue PHPOffice#2609 and PR PHPOffice#2438). Although the deprecation message is suppressed, users with a homegrown error handler may still see it. I am not very concerned about that symptom, but I imagine that there will be more similar tickets in future. This PR adds a new property/method to Reader/CSV to allow the user to avoid the deprecated code, at the negligible cost of being unable to read a CSV with Mac line endings even on a Php version that could support it.
oleibman added a commit that referenced this pull request Mar 1, 2022
With the deprecation of `auto_detect_line_endings` in Php8.1, there have been some tickets (issue #2609 and PR #2438). Although the deprecation message is suppressed, users with a homegrown error handler may still see it. I am not very concerned about that symptom, but I imagine that there will be more similar tickets in future. This PR adds a new property/method to Reader/CSV to allow the user to avoid the deprecated code, at the negligible cost of being unable to read a CSV with Mac line endings even on a Php version that could support it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants