php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75031 Stream php://temp incorrectly implements A+ mode
Submitted: 2017-08-03 21:51 UTC Modified: -
Votes:3
Avg. Score:3.3 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: jocrutrisi at ibsats dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 7.2.0beta2 OS: All
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jocrutrisi at ibsats dot com
New email:
PHP Version: OS:

 

 [2017-08-03 21:51 UTC] jocrutrisi at ibsats dot com
Description:
------------
The example demonstrates a discrepancy in A+ mode between a file stream, and a php://temp stream.

According to docs, the file stream is correct, and php://temp is wrong here. 

Interesting this is not new, apparently all PHP versions do this, even HHVM:

https://3v4l.org/6KlYg

But both streams should behave the same, so something is off.

Test script:
---------------
<?php
function test($a) {
    fwrite($a, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    fseek($a, 0);
    fwrite($a, '1234567890');
    fseek($a, 0);
    var_dump(fread($a, 1024));
    fclose($a);
}

$a = fopen('php://temp', 'a+');
test($a);

echo '-------------------' . PHP_EOL;

$a = fopen(tempnam(sys_get_temp_dir(), "hello"), 'a+');
test($a);

Expected result:
----------------
string(36) "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
-------------------
string(36) "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

Actual result:
--------------
string(26) "1234567890KLMNOPQRSTUVWXYZ"
-------------------
string(36) "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-04 11:44 UTC] krakjoe@php.net
Automatic comment on behalf of as
Revision: http://git.php.net/?p=php-src.git;a=commit;h=db96b7c245907ef533c9dd7dc226b839df1a9341
Log: Fix #75031: Support append mode in `php://temp` streams
 [2017-08-04 11:44 UTC] krakjoe@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC