-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
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.
The failed test for PHP 8.1 does fail, as the version detection disable
|
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;
}
); |
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. |
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. |
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.
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.
This is:
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.