-
-
Notifications
You must be signed in to change notification settings - Fork 339
Description
In PHP8.4 the escape parameter is deprecated to use with csv methods and functions in PHP.
- The only value acceptable is the empty string.
- Any other valid value (ie. any one byte long character) will trigger a deprecation warning.
- Invalid value behaviour does not change
- The deprecation warning will be emitted on each method/function call
This means for league/csv that
- the current default value for the escape character will emit the deprecation
- every time a insertion or a read is performed using a non empty value a deprecation will be triggered.
$reader = Reader::createFromPath('path/to/document.csv');
foreach ($reader as $record) {
// on each iteration a deprecation warning is issued starting with PHP8.4!
}
$writer = Writer::createFromString();
$writer->insertAll($records);
// on each insertion a deprecation warning is issued starting with PHP8.4!
An easy workaround would be to tell users via documentation and communication that they now need to do the following:
$reader = Reader::createFromPath('path/to/document.csv');
$reader->setEscape('');
foreach ($reader as $record) {
// no deprecation warning at all
}
$writer = Writer::createFromString();
$writer->setEscape('');
$writer->insertAll($records);
// no deprecation warning at all
But since the end goal it to remove the escape character mechanism completely this means that setEscape
and getEscape
should also be deprecated which leads to a chicken and a egg issue. If you are on version 9 to fix the issue in 8.4 you need to add a method call which will be removed once you are on version 10 with PHP8.4 or PHP9. Which adds burden to migration.
Another way to deal with this issue would be to release a new major version of league/csv with the escape mechanism removed entirely and internally always using the empty string. This is possible for every supported version of PHP. But releasing a new major version only for this is cumbersome as they are other major area of the package that would benefit for a clean up and an upgrade and the time constraint before the release of PHP8.4 is limiting the time to refactor correctly the package in a state that would be satisfying from maintenance POV.
Of course we could think of other strategies or solutions if you have one, you are welcomed to submit them in the comment