PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File Formats » File_CSV » Bug #5652

Static $config causes error with several CSV-objects

Details

Submitted2005-10-10 22:51 UTC
Fromblinky at gmx dot net
Assigneddufuz
StatusBogus
PackageFile_CSV
PHP Version4.3.10
OSLinux 2.6.12
Roadmaps(Not assigned)

Comments

[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)