diff --git a/UPGRADING b/UPGRADING index c981849a6012..197e961ec1fd 100644 --- a/UPGRADING +++ b/UPGRADING @@ -48,6 +48,9 @@ PHP 8.3 UPGRADE NOTES . C functions that have a return type of void now return null instead of returning the following object object(FFI\CData:void) { } +- Filesystem: + . file() flags error check now catches all invalid flags, notably FILE_APPEND, previously some invalid flags were silently accepted ( https://github.com/php/php-src/pull/11483 ) + - Standard: . The range() function has had various changes: * A TypeError is now thrown when passing objects, resources, or arrays @@ -355,3 +358,6 @@ PHP 8.3 UPGRADE NOTES ======================================== 14. Performance Improvements ======================================== + +- Filesystem: + . file() flags error check is now about 7% faster ( https://github.com/php/php-src/pull/11483 ) diff --git a/ext/standard/file.c b/ext/standard/file.c index f06b672fb673..f6076438f69d 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -619,7 +619,7 @@ PHP_FUNCTION(file) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { + if ((flags & ~(PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) != 0) { zend_argument_value_error(2, "must be a valid flag value"); RETURN_THROWS(); } diff --git a/ext/standard/tests/file/file_error.phpt b/ext/standard/tests/file/file_error.phpt index 163943a3db39..69bb93c0b7ae 100644 --- a/ext/standard/tests/file/file_error.phpt +++ b/ext/standard/tests/file/file_error.phpt @@ -7,8 +7,16 @@ echo "\n*** Testing error conditions ***\n"; $file_handle = fopen($file_path."/file.tmp", "w"); $filename = $file_path."/file.tmp"; -var_dump( file($filename, 10, NULL) ); // Incorrect flag - +try { + var_dump( file($filename, 10, NULL) ); // Incorrect flag +} catch(ValueError $e) { + echo "ValueError: " . $e->getMessage() . "\n"; +} +try { + var_dump( file($filename, FILE_APPEND) ); // Incorrect flag +} catch(ValueError $e) { + echo "ValueError: " . $e->getMessage() . "\n"; +} var_dump( file("temp.tmp") ); // non existing filename fclose($file_handle); @@ -21,8 +29,8 @@ unlink($file_path."/file.tmp"); ?> --EXPECTF-- *** Testing error conditions *** -array(0) { -} +ValueError: file(): Argument #2 ($flags) must be a valid flag value +ValueError: file(): Argument #2 ($flags) must be a valid flag value Warning: file(temp.tmp): Failed to open stream: No such file or directory in %s on line %d bool(false) diff --git a/ext/standard/tests/file/file_variation6.phpt b/ext/standard/tests/file/file_variation6.phpt index 6444c7f36675..9bd91cfd40de 100644 --- a/ext/standard/tests/file/file_variation6.phpt +++ b/ext/standard/tests/file/file_variation6.phpt @@ -95,78 +95,14 @@ array(3) { [2]=> string(6) "Line 3" } -array(3) { - [0]=> - string(7) "Line 1 -" - [1]=> - string(7) "Line 2 -" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(7) "Line 1 -" - [1]=> - string(7) "Line 2 -" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(6) "Line 1" - [1]=> - string(6) "Line 2" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(6) "Line 1" - [1]=> - string(6) "Line 2" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(7) "Line 1 -" - [1]=> - string(7) "Line 2 -" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(7) "Line 1 -" - [1]=> - string(7) "Line 2 -" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(6) "Line 1" - [1]=> - string(6) "Line 2" - [2]=> - string(6) "Line 3" -} -array(3) { - [0]=> - string(6) "Line 1" - [1]=> - string(6) "Line 2" - [2]=> - string(6) "Line 3" -} +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value +file(): Argument #2 ($flags) must be a valid flag value array(3) { [0]=> string(7) "Line 1