@@ -62,8 +62,19 @@ class Csv extends BaseReader
62
62
63
63
/**
64
64
* The character that can escape the enclosure.
65
+ * This will probably become unsupported in Php 9.
66
+ * Not yet ready to mark deprecated in order to give users
67
+ * a migration path.
65
68
*/
66
- private string $ escapeCharacter = '\\' ;
69
+ private ?string $ escapeCharacter = null ;
70
+
71
+ /**
72
+ * The character that will be supplied to fgetcsv
73
+ * when escapeCharacter is null.
74
+ * It is anticipated that it will conditionally be set
75
+ * to null-string for Php9 and above.
76
+ */
77
+ private static string $ defaultEscapeCharacter = '\\' ;
67
78
68
79
/**
69
80
* Callback for setting defaults in construction.
@@ -185,7 +196,7 @@ protected function inferSeparator(): void
185
196
return ;
186
197
}
187
198
188
- $ inferenceEngine = new Delimiter ($ this ->fileHandle , $ this ->escapeCharacter , $ this ->enclosure );
199
+ $ inferenceEngine = new Delimiter ($ this ->fileHandle , $ this ->escapeCharacter ?? self :: $ defaultEscapeCharacter , $ this ->enclosure );
189
200
190
201
// If number of lines is 0, nothing to infer : fall back to the default
191
202
if ($ inferenceEngine ->linesCounted () === 0 ) {
@@ -527,6 +538,11 @@ public function getContiguous(): bool
527
538
return $ this ->contiguous ;
528
539
}
529
540
541
+ /**
542
+ * Php9 intends to drop support for this parameter in fgetcsv.
543
+ * Not yet ready to mark deprecated in order to give users
544
+ * a migration path.
545
+ */
530
546
public function setEscapeCharacter (string $ escapeCharacter ): self
531
547
{
532
548
$ this ->escapeCharacter = $ escapeCharacter ;
@@ -536,7 +552,7 @@ public function setEscapeCharacter(string $escapeCharacter): self
536
552
537
553
public function getEscapeCharacter (): string
538
554
{
539
- return $ this ->escapeCharacter ;
555
+ return $ this ->escapeCharacter ?? self :: $ defaultEscapeCharacter ;
540
556
}
541
557
542
558
/**
@@ -664,8 +680,9 @@ private static function getCsv(
664
680
?int $ length = null ,
665
681
string $ separator = ', ' ,
666
682
string $ enclosure = '" ' ,
667
- string $ escape = '\\'
683
+ ? string $ escape = null
668
684
): array |false {
685
+ $ escape = $ escape ?? self ::$ defaultEscapeCharacter ;
669
686
if (PHP_VERSION_ID >= 80400 && $ escape !== '' ) {
670
687
return @fgetcsv ($ stream , $ length , $ separator , $ enclosure , $ escape );
671
688
}
0 commit comments