Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.0

Bug #5652 Static $config causes error with several CSV-objects
Submitted: 2005-10-10 22:51 UTC
From: blinky at gmx dot net Assigned: dufuz
Status: Bogus Package: File_CSV
PHP Version: 4.3.10 OS: Linux 2.6.12
Roadmaps: (Not assigned)    
Subscription  


 [2005-10-10 22:51 UTC] blinky at gmx dot net
Description: ------------ With several objects based upon File_CSV there will be problems in loops with read() and write() calls when they have different configuration (5 vs. 42 fields). Test script: --------------- $csvFile = new File_CSV(); $outFile = new File_CSV(); $csvfileformat = $csvFile->discoverFormat($csvfilename); $csvoutformat = array('fields' => 5, 'sep' => ';', 'quote' => '"'); while ($csv_line = $csvFile->read($csvfilename, $csvfileformat)) { $outarray[] = $csv_line[0]; $outarray[] = $csv_line[1]; $outarray[] = $csv_line[23]; $outarray[] = $csv_line[33]; $outarray[] = $csv_line[43]; $outFile->write($outfilename, $outarray, $csvoutformat); } Bugfix description below. Expected result: ---------------- The first line in the output file will contain 5 fields with the correct value. The second line (after the first call of write() with the other configuration) will only contain the first and second value since read() only reads 5 fields instead of 42. I could fix this problem by changing the file CSV.php like this: 1. Adding "var $config;" after "class File_CSV {" 2. In function "getPointer" I removed "static $config". 3. In "getPointer" I replaced "$config" by "$this->config". (near lines 138 and 148)

Comments

 [2005-10-11 01:01 UTC] dufuz
the fix you suggested won't cut it, we also support calling methods statically so we can't do this since the static way would break for people, so I'm not all that sure we can fix this problem in a elegant way, your best bet would be to read into a array and then instance the write object and iterate the read array instead of trying to do that within the read while loop.
 [2011-03-19 03:46 UTC] dufuz (Helgi Þormar Þorbjörnsson)
-Status: Assigned +Status: Bogus
This specific package is meant to be used in a static manner.