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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sjon at hortensius dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 14:01:32 2024 UTC