@@ -267,7 +267,8 @@ static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
267
267
/* }}} */
268
268
269
269
/* {{{ spl_filesystem_dir_open */
270
- /* open a directory resource */
270
+ /* open a directory resource
271
+ * Can emit an E_WARNING as it reports errors from php_stream_opendir() */
271
272
static void spl_filesystem_dir_open (spl_filesystem_object * intern , zend_string * path )
272
273
{
273
274
int skip_dots = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_SKIPDOTS );
@@ -297,7 +298,9 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_string *
297
298
}
298
299
/* }}} */
299
300
300
- static int spl_filesystem_file_open (spl_filesystem_object * intern , int use_include_path , int silent ) /* {{{ */
301
+ /* Can generate E_WARNINGS as we report errors from stream initialized via
302
+ * php_stream_open_wrapper_ex() */
303
+ static zend_result spl_filesystem_file_open (spl_filesystem_object * intern , bool use_include_path ) /* {{{ */
301
304
{
302
305
zval tmp ;
303
306
@@ -441,7 +444,6 @@ static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_o
441
444
{
442
445
spl_filesystem_object * intern ;
443
446
zval arg1 ;
444
- zend_error_handling error_handling ;
445
447
446
448
if (!file_path || !ZSTR_LEN (file_path )) {
447
449
#ifdef PHP_WIN32
@@ -450,8 +452,6 @@ static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_o
450
452
return NULL ;
451
453
}
452
454
453
- zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
454
-
455
455
ce = ce ? ce : source -> info_class ;
456
456
457
457
intern = spl_filesystem_from_obj (spl_filesystem_object_new_ex (ce ));
@@ -465,7 +465,6 @@ static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_o
465
465
spl_filesystem_info_set_filename (intern , file_path );
466
466
}
467
467
468
- zend_restore_error_handling (& error_handling );
469
468
return intern ;
470
469
} /* }}} */
471
470
@@ -556,8 +555,9 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
556
555
intern -> u .file .open_mode = zend_string_copy (open_mode );
557
556
intern -> u .file .zcontext = resource ;
558
557
558
+ /* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
559
559
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
560
- if (spl_filesystem_file_open (intern , use_include_path , 0 ) == FAILURE ) {
560
+ if (spl_filesystem_file_open (intern , use_include_path ) == FAILURE ) {
561
561
zend_restore_error_handling (& error_handling );
562
562
zval_ptr_dtor (return_value );
563
563
ZVAL_NULL (return_value );
@@ -733,6 +733,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
733
733
}
734
734
intern -> flags = flags ;
735
735
736
+ /* spl_filesystem_dir_open() may emit an E_WARNING */
736
737
zend_replace_error_handling (EH_THROW , spl_ce_UnexpectedValueException , & error_handling );
737
738
#ifdef HAVE_GLOB
738
739
if (SPL_HAS_FLAG (ctor_flags , DIT_CTOR_GLOB ) && memcmp (ZSTR_VAL (path ), "glob://" , sizeof ("glob://" )- 1 ) != 0 ) {
@@ -745,10 +746,9 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
745
746
spl_filesystem_dir_open (intern , path );
746
747
747
748
}
749
+ zend_restore_error_handling (& error_handling );
748
750
749
751
intern -> u .dir .is_recursive = instanceof_function (intern -> std .ce , spl_ce_RecursiveDirectoryIterator ) ? 1 : 0 ;
750
-
751
- zend_restore_error_handling (& error_handling );
752
752
}
753
753
/* }}} */
754
754
@@ -1225,17 +1225,13 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
1225
1225
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
1226
1226
ssize_t ret ;
1227
1227
char buff [MAXPATHLEN ];
1228
- zend_error_handling error_handling ;
1229
1228
1230
1229
if (zend_parse_parameters_none () == FAILURE ) {
1231
1230
RETURN_THROWS ();
1232
1231
}
1233
1232
1234
- zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
1235
-
1236
1233
if (intern -> file_name == NULL ) {
1237
1234
if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1238
- zend_restore_error_handling (& error_handling );
1239
1235
RETURN_THROWS ();
1240
1236
}
1241
1237
}
@@ -1247,7 +1243,6 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
1247
1243
if (!IS_ABSOLUTE_PATH (ZSTR_VAL (intern -> file_name ), ZSTR_LEN (intern -> file_name ))) {
1248
1244
char expanded_path [MAXPATHLEN ];
1249
1245
if (!expand_filepath_with_mode (ZSTR_VAL (intern -> file_name ), expanded_path , NULL , 0 , CWD_EXPAND )) {
1250
- zend_restore_error_handling (& error_handling );
1251
1246
php_error_docref (NULL , E_WARNING , "No such file or directory" );
1252
1247
RETURN_FALSE ;
1253
1248
}
@@ -1268,8 +1263,6 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
1268
1263
1269
1264
RETVAL_STRINGL (buff , ret );
1270
1265
}
1271
-
1272
- zend_restore_error_handling (& error_handling );
1273
1266
}
1274
1267
/* }}} */
1275
1268
@@ -1279,17 +1272,13 @@ PHP_METHOD(SplFileInfo, getRealPath)
1279
1272
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
1280
1273
char buff [MAXPATHLEN ];
1281
1274
char * filename ;
1282
- zend_error_handling error_handling ;
1283
1275
1284
1276
if (zend_parse_parameters_none () == FAILURE ) {
1285
1277
RETURN_THROWS ();
1286
1278
}
1287
1279
1288
- zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
1289
-
1290
1280
if (intern -> type == SPL_FS_DIR && !intern -> file_name && intern -> u .dir .entry .d_name [0 ]) {
1291
1281
if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1292
- zend_restore_error_handling (& error_handling );
1293
1282
RETURN_THROWS ();
1294
1283
}
1295
1284
}
@@ -1311,8 +1300,6 @@ PHP_METHOD(SplFileInfo, getRealPath)
1311
1300
} else {
1312
1301
RETVAL_FALSE ;
1313
1302
}
1314
-
1315
- zend_restore_error_handling (& error_handling );
1316
1303
}
1317
1304
/* }}} */
1318
1305
@@ -2061,29 +2048,31 @@ PHP_METHOD(SplFileObject, __construct)
2061
2048
RETURN_THROWS ();
2062
2049
}
2063
2050
2064
- zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
2065
-
2066
2051
intern -> u .file .open_mode = zend_string_copy (open_mode );
2067
- if (spl_filesystem_file_open (intern , use_include_path , 0 ) == SUCCESS ) {
2068
- path_len = strlen (intern -> u .file .stream -> orig_path );
2069
2052
2070
- if (path_len > 1 && IS_SLASH_AT (intern -> u .file .stream -> orig_path , path_len - 1 )) {
2071
- path_len -- ;
2072
- }
2053
+ /* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
2054
+ zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
2055
+ zend_result retval = spl_filesystem_file_open (intern , use_include_path );
2056
+ zend_restore_error_handling (& error_handling );
2057
+ if (retval == FAILURE ) {
2058
+ RETURN_THROWS ();
2059
+ }
2073
2060
2074
- while (path_len > 1 && !IS_SLASH_AT (intern -> u .file .stream -> orig_path , path_len - 1 )) {
2075
- path_len -- ;
2076
- }
2061
+ path_len = strlen (intern -> u .file .stream -> orig_path );
2077
2062
2078
- if (path_len ) {
2079
- path_len -- ;
2080
- }
2063
+ if (path_len > 1 && IS_SLASH_AT ( intern -> u . file . stream -> orig_path , path_len - 1 ) ) {
2064
+ path_len -- ;
2065
+ }
2081
2066
2082
- intern -> path = zend_string_init (intern -> u .file .stream -> orig_path , path_len , 0 );
2067
+ while (path_len > 1 && !IS_SLASH_AT (intern -> u .file .stream -> orig_path , path_len - 1 )) {
2068
+ path_len -- ;
2083
2069
}
2084
2070
2085
- zend_restore_error_handling (& error_handling );
2071
+ if (path_len ) {
2072
+ path_len -- ;
2073
+ }
2086
2074
2075
+ intern -> path = zend_string_init (intern -> u .file .stream -> orig_path , path_len , 0 );
2087
2076
} /* }}} */
2088
2077
2089
2078
/* {{{ Construct a new temp file object */
@@ -2108,8 +2097,9 @@ PHP_METHOD(SplTempFileObject, __construct)
2108
2097
intern -> file_name = file_name ;
2109
2098
intern -> u .file .open_mode = zend_string_init ("wb" , sizeof ("wb" )- 1 , 0 );
2110
2099
2100
+ /* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
2111
2101
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
2112
- if (spl_filesystem_file_open (intern , 0 , 0 ) == SUCCESS ) {
2102
+ if (spl_filesystem_file_open (intern , /* use_include_path */ false ) == SUCCESS ) {
2113
2103
intern -> path = ZSTR_EMPTY_ALLOC ();
2114
2104
}
2115
2105
zend_string_release (file_name );
0 commit comments