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

Bug #4548 $_File_Archive_Options not global
Submitted: 2005-06-07 22:54 UTC
From: tier at gregor-widuch dot de Assigned: vincentlascaux
Status: Closed Package: File_Archive
PHP Version: 4.3.8 OS: Windows XP Pro
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 49 - 31 = ?

 
 [2005-06-07 22:54 UTC] tier at gregor-widuch dot de
Description: ------------ In file Archive.php variable $_File_Archive_Options needs to be set global: global $_File_Archive_Options; $_File_Archive_Options = array( 'zipCompressionLevel' => 9, 'gzCompressionLevel' => 9, 'tmpDirectory' => '.', 'cache' => null, 'appendRemoveDuplicates' => false );

Comments

 [2005-06-07 23:10 UTC] vincentlascaux
I really doubt so. I think global must be used only inside functions, to tell PHP that the variable is not a local variable. This is done in File_Archive::setOption and File_Archive::getOption. If you think I'm wrong, please reopen the bug report, giving of PHP code that shows that File_Archive doesn't behave as expected, due to this lack of global. Thank you
 [2005-06-08 08:05 UTC] tier at gregor-widuch dot de
$_File_Archive_Options should be set global because some people maybe wants to use File_Archive inside a function or class. function zipMyData($filename, $exportFilename, $data) { require_once "File/Archive.php"; $rd = ""; $zipfile = File_Archive::toArchive($filename, File_Archive::toVariable($rd)); $zipfile->newFile($exportFilename, array()); $zipfile->writeData($renderedData); $zipfile->close(); return $rd; } if $_File_Archive_Options is not set to global the code generates a zip archive but the data is not zipped (I think compressed with level 0). The zipped file is really larger than the original data (but it is not corrupt)
 [2005-06-08 09:33 UTC] vincentlascaux
I still think you are wrong: the global should only be used inside the functions that will use $_File_Archive_Options directly. Since you should not use it, but use the File_Archive::setOption and File_Archive::getOption, you do not have to declare the variable global. Furthermore, I tested your code. The following code creates a string with char a repeated 10 000 times (and thus can be compressed easily). It then compresses it using your function, and displays the compressed and uncompressed size for each compression factor. <?php require_once "File/Archive.php"; PEAR::setErrorHandling(PEAR_ERROR_PRINT); function zipMyData($filename, $exportFilename, $data) { require_once "File/Archive.php"; $rd = ""; $zipfile = File_Archive::toArchive($filename, File_Archive::toVariable($rd)); $zipfile->newFile($exportFilename, array()); $zipfile->writeData($data); $zipfile->close(); return $rd; } $data = ''; for($i=0; $i<10000; $i++) $data .= 'a'; for($i=0; $i<10; $i++) { File_Archive::setOption("zipCompressionLevel", $i); $compressed = zipMyData('test.zip', 'inner.txt', $data); echo "$i: ".strlen($compressed).'/'.strlen($data)."\n"; } ?> When I run it, it displays the following: 0: 10121/10000 1: 178/10000 2: 178/10000 3: 178/10000 4: 144/10000 5: 144/10000 6: 144/10000 7: 144/10000 8: 144/10000 9: 144/10000 This proves that the File_Archive::setOption does have an influence.
 [2005-06-08 11:46 UTC] tier at gregor-widuch dot de
First let me say: it´s a great great class you wrote. What I reported is maybe not a bug. But it me hours to get it to work. So it would be nice for users to know it. A last remark: In your last sample you put the line require_once "File/Archive.php"; outside the function zipMyData. That is not what I wanted do. If I have the require_once line only in the function no compression is made: function zipMyData($filename, $exportFilename, $data) { require_once "File/Archive.php"; $rd = ""; $zipfile = File_Archive::toArchive($filename, File_Archive::toVariable($rd)); $zipfile->newFile($exportFilename, array()); $zipfile->writeData($data); $zipfile->close(); return $rd; } $data = ''; for($i=0; $i<10000; $i++) $data .= 'a'; $compressed = zipMyData('test.zip', 'inner.txt', $data); echo strlen($compressed).'/'.strlen($data)."\n"; Outputs: 10121/10000
 [2005-06-08 11:58 UTC] vincentlascaux
Oh, you have a point here... I have the good expected output (144/10000) on my PHP5, windows XP pro. It looks like a PHP bug. Apparently, putting the global keyword is a good work around for your PHP version. I'm investigating to see if it won't raise other problems for other versions. Sorry if I didn't understand your bug at first.
 [2005-06-08 12:24 UTC] vincentlascaux
Can you confirm that it solve the problem to put in Archive.php the following code: $GLOBALS['_File_Archive_Options'] = array( 'zipCompressionLevel' => 9, 'gzCompressionLevel' => 9, 'tmpDirectory' => '.', 'cache' => null, 'appendRemoveDuplicates' => false ); (with no global keyword) Thanks
 [2005-06-08 13:12 UTC] vincentlascaux
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/File_Archive This has been fixed using static function variables