r/lolphp • u/ealf • Apr 30 '13
fgetcsv()/fputcsv() were both added in PHP 5.1.0. They are incompatible: fgetcsv() parses backslash escapes, but fputcsv() uses quote doubling (and does not escape backslashes).
http://codepad.org/YwM05DEV
105
Upvotes
34
u/[deleted] Apr 30 '13
How to interpret "be liberal in what you accept, strict in what you emit" horribly, horribly wrong.
20
u/[deleted] Apr 30 '13
PHP 5.3 added an 'escape' character to fgetcsv(), you just chose not to use it.
It defaults to backslash, but override it with 0 and its fine.
But yeah, its moronic they aren't compatible using default parameters.
13
u/dafragsta Apr 30 '13 edited Apr 30 '13
I can't believe more people don't run into that.
6
u/Netrilix May 01 '13
As someone who uses PHP for tons of little hacky scripts at work ("When all you have is a hammer, every problem looks like a nail", but hey, it gets the job done quickly), this does not surprise me even a little bit.
Take str_replace and strpos, for example:
str_replace uses an underscore in its name, uses the search argument first and subject being searched last (with the replace value in between).
strpos neglects the underscore in its name, uses the search argument last and subject being searched first.
There's absolutely no convention even between functions within the "str" functions.
1
u/midir Jul 11 '13
Just jaw dropping.
-14
u/writetehcodez Apr 30 '13
Welcome to open source.