Skip to content

It's impossible to set the CSV delimiter to null after it is set to another value. #2287

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
ozanhazer opened this issue Sep 5, 2021 · 1 comment

Comments

@ozanhazer
Copy link

ozanhazer commented Sep 5, 2021

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

We should be able to set the delimiter to null so that the delimiter is inferred from the file.

$reader->setDelimiter(',');
$reader->setDelimiter(null); // throws TypeError

Laravel-excel package sets the delimiter to a comma by default (for performance issues I guess) and it's not possible to set it back to null afterwards. See also laravel-excel #3346

What is the current behavior?

It throws TypeError since the signature of \PhpOffice\PhpSpreadsheet\Reader\Csv::setDelimiter does not allow null values.

Which versions of PhpSpreadsheet and PHP are affected?

v1.17.* is fine, got the error with v1.18 and php8.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Sep 5, 2021
See issue PHPOffice#2287. A 1-character change. The delimiter variable is defined as nullable, and getDelimiter can return null; setDelimiter should follow suit.
oleibman added a commit that referenced this issue Sep 15, 2021
* Permit CSV Delimiter to be Set to Null

See issue #2287. A 1-character change. The delimiter variable is defined as nullable, and getDelimiter can return null; setDelimiter should follow suit.

* Scrutinizer Inanity

Are you sure the test always returns null?????
Yes, I'm sure, that's why it's part of the test.
Let's see if we can recode it and miss this "problem".
@PowerKiKi
Copy link
Member

Fixed in 1.19.0

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

2 participants