php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76900 overwriting start of stream truncates the end
Submitted: 2018-09-18 14:06 UTC Modified: 2018-09-18 14:13 UTC
From: sjon at hortensius dot net Assigned:
Status: Not a bug Package: Streams related
PHP Version: 7.3.0RC1 OS: archLinux
Private report: No CVE-ID: None
 [2018-09-18 14:06 UTC] sjon at hortensius dot net
Description:
------------
after fseeking a stream and fwriting less data to it, the previous available data is gone

See https://3v4l.org/2haHa

Test script:
---------------
<?php

$socket = fopen('php://memory', 'a+');
fwrite($socket, 'ab');
fseek($socket, 0);

fwrite($socket, 'a');

var_dump(fgets($socket));

Expected result:
----------------
string(1) "b"

Actual result:
--------------
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-18 14:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-09-18 14:13 UTC] requinix@php.net
See bug #75031.

http://php.net/manual/en/function.fopen.php
> 'a+'
> ...In this mode, fseek() only affects the reading position, writes are always appended.
 [2018-09-18 23:51 UTC] a at b dot c dot de
As for "the previous available data is gone" bit...

<?php

$socket = fopen('php://memory', 'a+');
fwrite($socket, 'ab');
fseek($socket, 0);

fwrite($socket, 'a');

fseek($socket, 0);

var_dump(fgets($socket));
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC