@@ -2042,22 +2042,21 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
2042
2042
PHP_METHOD (SplFileObject , __construct )
2043
2043
{
2044
2044
spl_filesystem_object * intern = spl_filesystem_from_obj (Z_OBJ_P (ZEND_THIS ));
2045
+ zend_string * file_name = NULL ;
2045
2046
zend_string * open_mode = ZSTR_CHAR ('r' );
2047
+ zval * stream_context = NULL ;
2046
2048
bool use_include_path = 0 ;
2047
2049
size_t path_len ;
2048
2050
zend_error_handling error_handling ;
2049
2051
2050
- intern -> u .file .open_mode = ZSTR_CHAR ('r' );
2051
-
2052
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" ,
2053
- & intern -> file_name , & open_mode ,
2054
- & use_include_path , & intern -> u .file .zcontext ) == FAILURE ) {
2055
- intern -> u .file .open_mode = NULL ;
2056
- intern -> file_name = NULL ;
2052
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" , & file_name , & open_mode , & use_include_path , & stream_context ) == FAILURE ) {
2057
2053
RETURN_THROWS ();
2058
2054
}
2059
2055
2060
2056
intern -> u .file .open_mode = zend_string_copy (open_mode );
2057
+ /* file_name and zcontext are copied by spl_filesystem_file_open() */
2058
+ intern -> file_name = file_name ;
2059
+ intern -> u .file .zcontext = stream_context ;
2061
2060
2062
2061
/* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
2063
2062
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
@@ -2096,6 +2095,12 @@ PHP_METHOD(SplTempFileObject, __construct)
2096
2095
RETURN_THROWS ();
2097
2096
}
2098
2097
2098
+ /* Prevent reinitialization of Object */
2099
+ if (intern -> u .file .stream ) {
2100
+ zend_throw_error (NULL , "Cannot call constructor twice" );
2101
+ RETURN_THROWS ();
2102
+ }
2103
+
2099
2104
if (max_memory < 0 ) {
2100
2105
file_name = zend_string_init ("php://memory" , sizeof ("php://memory" )- 1 , 0 );
2101
2106
} else if (ZEND_NUM_ARGS ()) {
0 commit comments