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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun Dec 22 01:01:30 2024 UTC