Bug #75031 [Com]: Stream php://temp incorrectly implements A+ mode
| From: | as@php.net | Date: | Fri, 04 Aug 2017 06:13:22 +0000 |
| Subject: | Bug #75031 [Com]: Stream php://temp incorrectly implements A+ mode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210472@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75031&edit=1
ID: 75031
Comment by: as@php.net
Reported by: jocrutrisi at ibsats dot com
Summary: Stream php://temp incorrectly implements A+ mode
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: All
PHP Version: 7.2.0beta2
Block user comment: N
Private report: N
New Comment:
https://github.com/php/php-src/pull/2671
Previous Comments:
------------------------------------------------------------------------
[2017-08-03 21:51:07] 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"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75031&edit=1