Skip to content

/src/PhpSpreadsheet/Reader/Csv.php:280 - auto_detect_line_endings is deprecated #2609

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

Closed
laurinkeithdavis opened this issue Feb 20, 2022 · 11 comments

Comments

@laurinkeithdavis
Copy link

I see the comment that this is deprecated, but I don't see an issue open to replace/remove this code, so I'm opening one as we just moved to 8.1 and are getting this warning. We'll suppress it for now, but just wanted to make sure it was addressed:

image

@oleibman
Copy link
Collaborator

The warning message is already suppressed. Why are you seeing a warning?

@laurinkeithdavis
Copy link
Author

We use a custom error handler and suppress only based on a set of rules. However, I did not create this for it to be suppressed, but for it to be fixed (replaced or removed).

@oleibman
Copy link
Collaborator

It will be removed when it is no longer supported. Deprecated or not, it is supported in 8.1, and removing might (agree that it is unlikely) be a problem for existing users. There is already a unit test in place which will fail when it is no longer supported, and we will respond to the test failure when that time comes.

@laurinkeithdavis
Copy link
Author

Ok, that's fine. Like I said, I did not see an issue open (or closed) for it, so I wanted to make sure it was not missed (or submit a patch if needed).

@oleibman
Copy link
Collaborator

Thank you for being proactive.

The test which will eventually fail is Reader/Csv/CsvLineEndingTest. I will leave this issue open for about a week to see if it sparks any other discussion.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue 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 issue 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.
@oleibman
Copy link
Collaborator

oleibman commented Mar 1, 2022

Closing. Merged PR 2623 to give people a means to avoid deprecation notice even with custom error handler. Test which will fail in Php9 should guarantee that the deprecation is not overlooked.

@Onerosolutions
Copy link

Onerosolutions commented Jun 13, 2023

I am still experiencing this issue in the latest PhpSpreadsheet. As a temporary solution, I have decided to comment out lines 365 and 425 in the src\PhpSpreadsheet\Reader\Csv.php file.

image

@oleibman
Copy link
Collaborator

There is no need to comment out any code. Add the following to your application instead.

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
$reader->setTestAutoDetect(false);

@Onerosolutions
Copy link

Onerosolutions commented Jun 15, 2023

There is no need to comment out any code. Add the following to your application instead.

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
$reader->setTestAutoDetect(false);

Aah. I see.
I actually tried something like that before. Because there is a setTestAutoDetect() method when I looked at the source code, but when I tried it, it says undefined.

image

It turns out the instance calling is different... So, I just need to modify the instance according to the input type, using either new \PhpOffice\PhpSpreadsheet\Reader\Csv() or Xlsx(), right?

image

@oleibman
Copy link
Collaborator

That should work. If you're not sure of the reader type, as in your first example, you might try:

if (method_exists($reader, 'setTestAutoDetect')) {
    $reader->setTestAutoDetect(false);
}

@Onerosolutions
Copy link

Ah, alright, got it. Thank you very much.

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

No branches or pull requests

3 participants