Doc #70819 [Com]: bzopen/fopen is not rewinded when accessing a file for the second time
| From: | mail at jerrygrey dot me | Date: | Sun, 01 Nov 2015 15:28:38 +0000 |
| Subject: | Doc #70819 [Com]: bzopen/fopen is not rewinded when accessing a file for the second time | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12851@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70819&edit=1
ID: 70819
Comment by: mail at jerrygrey dot me
Reported by: mail at jerrygrey dot me
Summary: bzopen/fopen is not rewinded when accessing a file
for the second time
Status: Open
Type: Documentation Problem
Package: Streams related
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
In that case, should this function exist at all? It is just causing confusion.
Previous Comments:
------------------------------------------------------------------------
[2015-11-01 15:20:20] reeze@php.net
This might be a document problem.
bzflush() is a no-op function, https://github.com/enthought/bzip2/blob/master/bzlib.c#L1505
You could close it before next reading.
<?php
$file = __DIR__ . DIRECTORY_SEPARATOR . 'bzflush_test.txt.bz2';
$text = "This is a test string.";
$bz1 = bzopen($file, 'w');
bzwrite($bz1, $text);
var_dump(bzflush($bz1));
var_dump(file_get_contents($file));
bzclose($bz1);
var_dump(file_get_contents($file));
------------------------------------------------------------------------
[2015-10-30 06:20:15] mail at jerrygrey dot me
Description:
------------
This looks like an old bug (from 12 years ago) first appearing here: http://php.net/manual/en/function.fflush.php#28887
It has reappeared via https://github.com/php/php-src/pull/1553
The function bzopen should automatically rewind the file pointer as per fopen() documentation for
"r" mode: "...place the file pointer at the beginning of the file", but it
doesn't. If this is by design, it should be included in the documentation. Since fopen is the
base for bzopen, it might have the same issue too.
Test script:
---------------
<?php
$file = __DIR__ . DIRECTORY_SEPARATOR . 'bzflush_test.txt.bz2';
$text = "This is a test string.";
$bz1 = bzopen($file, 'w');
bzwrite($bz1, $text);
var_dump(bzflush($bz1));
$bz2 = bzopen($file, 'r');
var_dump(bzread($bz2));
bzclose($bz2);
bzclose($bz1);
?>
Expected result:
----------------
bool(true)
string(22) "This is a test string."
Actual result:
--------------
bool(true)
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70819&edit=1