File tree 4 files changed +26
-77
lines changed
4 files changed +26
-77
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ PHP 8.3 UPGRADE NOTES
68
68
* range() now produce a list of characters if one of the boundary inputs is
69
69
a string digit instead of casting the other input to int
70
70
(e.g. range('5', 'z');)
71
+ . The file() flags error check now catches all invalid flags. Notably
72
+ FILE_APPEND was previously silently accepted.
71
73
72
74
========================================
73
75
2. New Features
@@ -355,3 +357,6 @@ PHP 8.3 UPGRADE NOTES
355
357
========================================
356
358
14. Performance Improvements
357
359
========================================
360
+
361
+ - Standard:
362
+ . The file() flags error check is now about 7% faster.
Original file line number Diff line number Diff line change @@ -619,7 +619,7 @@ PHP_FUNCTION(file)
619
619
Z_PARAM_RESOURCE_OR_NULL (zcontext )
620
620
ZEND_PARSE_PARAMETERS_END ();
621
621
622
- if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT )) {
622
+ if (( flags & ~ (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT )) != 0 ) {
623
623
zend_argument_value_error (2 , "must be a valid flag value" );
624
624
RETURN_THROWS ();
625
625
}
Original file line number Diff line number Diff line change @@ -7,8 +7,16 @@ echo "\n*** Testing error conditions ***\n";
7
7
$ file_handle = fopen ($ file_path ."/file.tmp " , "w " );
8
8
9
9
$ filename = $ file_path ."/file.tmp " ;
10
- var_dump ( file ($ filename , 10 , NULL ) ); // Incorrect flag
11
-
10
+ try {
11
+ var_dump ( file ($ filename , 10 , NULL ) ); // Incorrect flag
12
+ } catch (ValueError $ e ) {
13
+ echo "ValueError: " . $ e ->getMessage () . "\n" ;
14
+ }
15
+ try {
16
+ var_dump ( file ($ filename , FILE_APPEND ) ); // Incorrect flag
17
+ } catch (ValueError $ e ) {
18
+ echo "ValueError: " . $ e ->getMessage () . "\n" ;
19
+ }
12
20
var_dump ( file ("temp.tmp " ) ); // non existing filename
13
21
fclose ($ file_handle );
14
22
@@ -21,8 +29,8 @@ unlink($file_path."/file.tmp");
21
29
?>
22
30
--EXPECTF--
23
31
*** Testing error conditions ***
24
- array(0) {
25
- }
32
+ ValueError: file(): Argument #2 ($flags) must be a valid flag value
33
+ ValueError: file(): Argument #2 ($flags) must be a valid flag value
26
34
27
35
Warning: file(temp.tmp): Failed to open stream: No such file or directory in %s on line %d
28
36
bool(false)
Original file line number Diff line number Diff line change @@ -95,78 +95,14 @@ array(3) {
95
95
[2]=>
96
96
string(6) "Line 3"
97
97
}
98
- array(3) {
99
- [0]=>
100
- string(7) "Line 1
101
- "
102
- [1]=>
103
- string(7) "Line 2
104
- "
105
- [2]=>
106
- string(6) "Line 3"
107
- }
108
- array(3) {
109
- [0]=>
110
- string(7) "Line 1
111
- "
112
- [1]=>
113
- string(7) "Line 2
114
- "
115
- [2]=>
116
- string(6) "Line 3"
117
- }
118
- array(3) {
119
- [0]=>
120
- string(6) "Line 1"
121
- [1]=>
122
- string(6) "Line 2"
123
- [2]=>
124
- string(6) "Line 3"
125
- }
126
- array(3) {
127
- [0]=>
128
- string(6) "Line 1"
129
- [1]=>
130
- string(6) "Line 2"
131
- [2]=>
132
- string(6) "Line 3"
133
- }
134
- array(3) {
135
- [0]=>
136
- string(7) "Line 1
137
- "
138
- [1]=>
139
- string(7) "Line 2
140
- "
141
- [2]=>
142
- string(6) "Line 3"
143
- }
144
- array(3) {
145
- [0]=>
146
- string(7) "Line 1
147
- "
148
- [1]=>
149
- string(7) "Line 2
150
- "
151
- [2]=>
152
- string(6) "Line 3"
153
- }
154
- array(3) {
155
- [0]=>
156
- string(6) "Line 1"
157
- [1]=>
158
- string(6) "Line 2"
159
- [2]=>
160
- string(6) "Line 3"
161
- }
162
- array(3) {
163
- [0]=>
164
- string(6) "Line 1"
165
- [1]=>
166
- string(6) "Line 2"
167
- [2]=>
168
- string(6) "Line 3"
169
- }
98
+ file(): Argument #2 ($flags) must be a valid flag value
99
+ file(): Argument #2 ($flags) must be a valid flag value
100
+ file(): Argument #2 ($flags) must be a valid flag value
101
+ file(): Argument #2 ($flags) must be a valid flag value
102
+ file(): Argument #2 ($flags) must be a valid flag value
103
+ file(): Argument #2 ($flags) must be a valid flag value
104
+ file(): Argument #2 ($flags) must be a valid flag value
105
+ file(): Argument #2 ($flags) must be a valid flag value
170
106
array(3) {
171
107
[0]=>
172
108
string(7) "Line 1
You can’t perform that action at this time.
0 commit comments