@@ -2035,22 +2035,21 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
20352035PHP_METHOD (SplFileObject , __construct )
20362036{
20372037 spl_filesystem_object * intern = spl_filesystem_from_obj (Z_OBJ_P (ZEND_THIS ));
2038+ zend_string * file_name = NULL ;
20382039 zend_string * open_mode = ZSTR_CHAR ('r' );
2040+ zval * stream_context = NULL ;
20392041 bool use_include_path = 0 ;
20402042 size_t path_len ;
20412043 zend_error_handling error_handling ;
20422044
2043- intern -> u .file .open_mode = ZSTR_CHAR ('r' );
2044-
2045- if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" ,
2046- & intern -> file_name , & open_mode ,
2047- & use_include_path , & intern -> u .file .zcontext ) == FAILURE ) {
2048- intern -> u .file .open_mode = NULL ;
2049- intern -> file_name = NULL ;
2045+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" , & file_name , & open_mode , & use_include_path , & stream_context ) == FAILURE ) {
20502046 RETURN_THROWS ();
20512047 }
20522048
20532049 intern -> u .file .open_mode = zend_string_copy (open_mode );
2050+ /* file_name and zcontext are copied by spl_filesystem_file_open() */
2051+ intern -> file_name = file_name ;
2052+ intern -> u .file .zcontext = stream_context ;
20542053
20552054 /* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
20562055 zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
@@ -2089,6 +2088,12 @@ PHP_METHOD(SplTempFileObject, __construct)
20892088 RETURN_THROWS ();
20902089 }
20912090
2091+ /* Prevent reinitialization of Object */
2092+ if (intern -> u .file .stream ) {
2093+ zend_throw_error (NULL , "Cannot call constructor twice" );
2094+ RETURN_THROWS ();
2095+ }
2096+
20922097 if (max_memory < 0 ) {
20932098 file_name = ZSTR_INIT_LITERAL ("php://memory" , 0 );
20942099 } else if (ZEND_NUM_ARGS ()) {
0 commit comments