xref: /PHP-8.3/ext/standard/tests/file/bug52335.phpt (revision ba9650d6)
1--TEST--
2Bug #52335 (fseek() on memory stream behavior different then file)
3--FILE--
4<?php
5
6echo "Read mode\n";
7$fpr = fopen("php://memory", "r");
8var_dump(fseek($fpr, 20));
9var_dump(feof($fpr));
10var_dump(ftell($fpr));
11var_dump(feof($fpr));
12var_dump(fread($fpr, 2));
13var_dump(feof($fpr));
14var_dump(fseek($fpr, 24));
15var_dump(feof($fpr));
16var_dump(ftell($fpr));
17fclose($fpr);
18
19echo "Read write mode\n";
20$fprw = fopen("php://memory", "r+");
21var_dump(fwrite($fprw, "data"));
22var_dump(fseek($fprw, 20, SEEK_END));
23var_dump(feof($fprw));
24var_dump(ftell($fprw));
25var_dump(feof($fprw));
26var_dump(fread($fprw, 2));
27var_dump(feof($fprw));
28var_dump(fseek($fprw, 20));
29var_dump(fwrite($fprw, " and more data"));
30var_dump(feof($fprw));
31var_dump(ftell($fprw));
32var_dump(fread($fprw, 10));
33var_dump(fseek($fprw, 16, SEEK_CUR));
34var_dump(ftell($fprw));
35var_dump(fseek($fprw, 0));
36var_dump(bin2hex(stream_get_contents($fprw)));
37fclose($fprw);
38
39?>
40--EXPECT--
41Read mode
42int(0)
43bool(false)
44int(20)
45bool(false)
46string(0) ""
47bool(true)
48int(0)
49bool(false)
50int(24)
51Read write mode
52int(4)
53int(0)
54bool(false)
55int(24)
56bool(false)
57string(0) ""
58bool(true)
59int(0)
60int(14)
61bool(false)
62int(34)
63string(0) ""
64int(0)
65int(50)
66int(0)
67string(68) "646174610000000000000000000000000000000020616e64206d6f72652064617461"
68