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
View Add Comment Developer Edit
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:
42 - 22 = ?
Subscribe to this entry?

 
 [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-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 03:01:28 2019 UTC