Skip to content

Commit 1cbcf0f

Browse files
committed
Throw notice for plain wrapper fread/fwrite errors
Similar to what is done for socket read/write errors.
1 parent dee243d commit 1cbcf0f

37 files changed

+954
-629
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ PHP 7.4 UPGRADE NOTES
142142
. fread() and fwrite() will now return false if the operation failed.
143143
Previously an empty string or 0 was returned. EAGAIN/EWOULDBLOCK are not
144144
considered failures.
145+
. fread() and fwrite() on plain files will now throw a notice on failure,
146+
such as when trying to write to a read-only file resource.
145147

146148
- Tokenizer:
147149
. token_get_all() will now emit a T_BAD_CHARACTER token for unexpected

ext/fileinfo/tests/bug61964-mb.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ rmdir($dir);
4545
?>
4646
===DONE===
4747
--EXPECTF--
48-
bool(false)
48+
bool(false)%A
4949
resource(%d) of type (file_info)
5050
resource(%d) of type (file_info)
51-
bool(false)
52-
51+
bool(false)%A
5352
Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964-mb.php on line %d
5453

5554
Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964-mb.php on line %d

ext/fileinfo/tests/bug61964.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ rmdir($dir);
4545
?>
4646
===DONE===
4747
--EXPECTF--
48-
bool(false)
48+
bool(false)%A
4949
resource(%d) of type (file_info)
5050
resource(%d) of type (file_info)
51-
bool(false)
52-
51+
bool(false)%A
5352
Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964.php on line %d
5453

5554
Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964.php on line %d

ext/standard/tests/file/007_variation1.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ int(0)
4848
string(20) "line
4949
line of text
5050
li"
51+
52+
Notice: fwrite(): write of 37 bytes failed with errno=9 Bad file descriptor in %s on line %d
5153
bool(false)
5254
bool(true)
5355
string(7) "Unknown"

ext/standard/tests/file/007_variation11-win32-mb.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ string(6) "stream"
6868
int(0)
6969
int(37)
7070
int(37)
71+
72+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
7173
bool(false)
7274
int(0)
7375
bool(true)

ext/standard/tests/file/007_variation11-win32.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ string(6) "stream"
6666
int(0)
6767
int(37)
6868
int(37)
69+
70+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
6971
bool(false)
7072
int(0)
7173
bool(true)

ext/standard/tests/file/007_variation11.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ string(6) "stream"
6666
int(0)
6767
int(37)
6868
int(37)
69+
70+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
6971
bool(false)
7072
int(0)
7173
bool(true)

ext/standard/tests/file/007_variation13-win32.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ unlink(__DIR__."/007_variation13.tmp");
5656
resource(%d) of type (stream)
5757
string(6) "stream"
5858
int(37)
59+
60+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5961
bool(false)
6062
int(0)
6163
bool(true)

ext/standard/tests/file/007_variation13.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ unlink(__DIR__."/007_variation13.tmp");
5656
resource(%d) of type (stream)
5757
string(6) "stream"
5858
int(37)
59+
60+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5961
bool(false)
6062
int(0)
6163
bool(true)

ext/standard/tests/file/007_variation15.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ string(6) "stream"
4949
int(0)
5050
int(37)
5151
int(37)
52+
53+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5254
bool(false)
5355
int(0)
5456
bool(true)

ext/standard/tests/file/007_variation17.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ int(0)
4848
string(20) "line
4949
line of text
5050
li"
51+
52+
Notice: fwrite(): write of 37 bytes failed with errno=9 Bad file descriptor in %s on line %d
5153
bool(false)
5254
bool(true)
5355
string(7) "Unknown"

ext/standard/tests/file/007_variation19.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ string(6) "stream"
6161
int(0)
6262
int(37)
6363
int(37)
64+
65+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
6466
bool(false)
6567
int(0)
6668
bool(true)

ext/standard/tests/file/007_variation21.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ unlink(__DIR__."/007_variation21.tmp");
5151
resource(%d) of type (stream)
5252
string(6) "stream"
5353
int(37)
54+
55+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5456
bool(false)
5557
int(0)
5658
bool(true)

ext/standard/tests/file/007_variation23.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ string(6) "stream"
4949
int(0)
5050
int(37)
5151
int(37)
52+
53+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5254
bool(false)
5355
int(0)
5456
bool(true)

ext/standard/tests/file/007_variation3.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ string(6) "stream"
6161
int(0)
6262
int(37)
6363
int(37)
64+
65+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
6466
bool(false)
6567
int(0)
6668
bool(true)

ext/standard/tests/file/007_variation5.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ unlink(__DIR__."/007_variation5.tmp");
5151
resource(%d) of type (stream)
5252
string(6) "stream"
5353
int(37)
54+
55+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5456
bool(false)
5557
int(0)
5658
bool(true)

ext/standard/tests/file/007_variation7.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ string(6) "stream"
4949
int(0)
5050
int(37)
5151
int(37)
52+
53+
Notice: fread(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5254
bool(false)
5355
int(0)
5456
bool(true)

ext/standard/tests/file/007_variation9.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ int(0)
4848
string(20) "line
4949
line of text
5050
li"
51+
52+
Notice: fwrite(): write of 37 bytes failed with errno=9 Bad file descriptor in %s on line %d
5153
bool(false)
5254
bool(true)
5355
string(7) "Unknown"

ext/standard/tests/file/bug35781.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var_dump(file_get_contents($filename));
1818

1919
echo "Done\n";
2020
?>
21-
--EXPECT--
21+
--EXPECTF--
22+
Notice: fpassthru(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
2223
string(15) "Guvf vf n grfg
2324
"
2425
Done

ext/standard/tests/file/fgetc_variation3.phpt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,68 +49,86 @@ foreach ($file_modes as $file_mode ) {
4949

5050
echo "Done\n";
5151
?>
52-
--EXPECT--
52+
--EXPECTF--
5353
*** Testing fgetc() with file opened in write only mode ***
5454
-- File opened in mode : w --
5555
bool(true)
5656
int(0)
5757
bool(false)
58+
59+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
5860
bool(false)
5961
int(0)
6062
bool(false)
6163
-- File opened in mode : wb --
6264
bool(true)
6365
int(0)
6466
bool(false)
67+
68+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
6569
bool(false)
6670
int(0)
6771
bool(false)
6872
-- File opened in mode : wt --
6973
bool(true)
7074
int(0)
7175
bool(false)
76+
77+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
7278
bool(false)
7379
int(0)
7480
bool(false)
7581
-- File opened in mode : a --
7682
bool(true)
7783
int(0)
7884
bool(false)
85+
86+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
7987
bool(false)
8088
int(0)
8189
bool(false)
8290
-- File opened in mode : ab --
8391
bool(true)
8492
int(0)
8593
bool(false)
94+
95+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
8696
bool(false)
8797
int(0)
8898
bool(false)
8999
-- File opened in mode : at --
90100
bool(true)
91101
int(0)
92102
bool(false)
103+
104+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
93105
bool(false)
94106
int(0)
95107
bool(false)
96108
-- File opened in mode : x --
97109
bool(true)
98110
int(0)
99111
bool(false)
112+
113+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
100114
bool(false)
101115
int(0)
102116
bool(false)
103117
-- File opened in mode : xb --
104118
bool(true)
105119
int(0)
106120
bool(false)
121+
122+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
107123
bool(false)
108124
int(0)
109125
bool(false)
110126
-- File opened in mode : xt --
111127
bool(true)
112128
int(0)
113129
bool(false)
130+
131+
Notice: fgetc(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
114132
bool(false)
115133
int(0)
116134
bool(false)

0 commit comments

Comments
 (0)