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

Bug #5652 Static $config causes error with several CSV-objects
Submitted: 2005-10-10 17:51 UTC Modified: 2007-08-11 16:13 UTC
From: blinky at gmx dot net Assigned: dufuz
Status: Assigned Package: File_CSV
PHP Version: 4.3.10 OS: Linux 2.6.12
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: blinky at gmx dot net
New email:
PHP Version: Package Version: OS:

 

 [2005-10-10 17: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-10 20: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.