@@ -2016,22 +2016,21 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
2016
2016
PHP_METHOD (SplFileObject , __construct )
2017
2017
{
2018
2018
spl_filesystem_object * intern = spl_filesystem_from_obj (Z_OBJ_P (ZEND_THIS ));
2019
+ zend_string * file_name = NULL ;
2019
2020
zend_string * open_mode = ZSTR_CHAR ('r' );
2021
+ zval * stream_context = NULL ;
2020
2022
bool use_include_path = 0 ;
2021
2023
size_t path_len ;
2022
2024
zend_error_handling error_handling ;
2023
2025
2024
- intern -> u .file .open_mode = ZSTR_CHAR ('r' );
2025
-
2026
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" ,
2027
- & intern -> file_name , & open_mode ,
2028
- & use_include_path , & intern -> u .file .zcontext ) == FAILURE ) {
2029
- intern -> u .file .open_mode = NULL ;
2030
- intern -> file_name = NULL ;
2026
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" , & file_name , & open_mode , & use_include_path , & stream_context ) == FAILURE ) {
2031
2027
RETURN_THROWS ();
2032
2028
}
2033
2029
2034
2030
intern -> u .file .open_mode = zend_string_copy (open_mode );
2031
+ /* file_name and zcontext are copied by spl_filesystem_file_open() */
2032
+ intern -> file_name = file_name ;
2033
+ intern -> u .file .zcontext = stream_context ;
2035
2034
2036
2035
/* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
2037
2036
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
@@ -2070,6 +2069,12 @@ PHP_METHOD(SplTempFileObject, __construct)
2070
2069
RETURN_THROWS ();
2071
2070
}
2072
2071
2072
+ /* Prevent reinitialization of Object */
2073
+ if (intern -> u .file .stream ) {
2074
+ zend_throw_error (NULL , "Cannot call constructor twice" );
2075
+ RETURN_THROWS ();
2076
+ }
2077
+
2073
2078
if (max_memory < 0 ) {
2074
2079
file_name = ZSTR_INIT_LITERAL ("php://memory" , 0 );
2075
2080
} else if (ZEND_NUM_ARGS ()) {
0 commit comments