@@ -2035,22 +2035,21 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
2035
2035
PHP_METHOD (SplFileObject , __construct )
2036
2036
{
2037
2037
spl_filesystem_object * intern = spl_filesystem_from_obj (Z_OBJ_P (ZEND_THIS ));
2038
+ zend_string * file_name = NULL ;
2038
2039
zend_string * open_mode = ZSTR_CHAR ('r' );
2040
+ zval * stream_context = NULL ;
2039
2041
bool use_include_path = 0 ;
2040
2042
size_t path_len ;
2041
2043
zend_error_handling error_handling ;
2042
2044
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 ) {
2050
2046
RETURN_THROWS ();
2051
2047
}
2052
2048
2053
2049
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 ;
2054
2053
2055
2054
/* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
2056
2055
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
@@ -2089,6 +2088,12 @@ PHP_METHOD(SplTempFileObject, __construct)
2089
2088
RETURN_THROWS ();
2090
2089
}
2091
2090
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
+
2092
2097
if (max_memory < 0 ) {
2093
2098
file_name = ZSTR_INIT_LITERAL ("php://memory" , 0 );
2094
2099
} else if (ZEND_NUM_ARGS ()) {
0 commit comments