@@ -2634,9 +2634,8 @@ PHP_FUNCTION(session_start)
26342634{
26352635 zval * options = NULL ;
26362636 zval * value ;
2637- zend_ulong num_idx ;
26382637 zend_string * str_idx ;
2639- zend_long read_and_close = 0 ;
2638+ bool read_and_close = false ;
26402639
26412640 if (zend_parse_parameters (ZEND_NUM_ARGS (), "|a" , & options ) == FAILURE ) {
26422641 RETURN_THROWS ();
@@ -2659,32 +2658,44 @@ PHP_FUNCTION(session_start)
26592658
26602659 /* set options */
26612660 if (options ) {
2662- ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P (options ), num_idx , str_idx , value ) {
2663- if (str_idx ) {
2664- switch (Z_TYPE_P (value )) {
2665- case IS_STRING :
2666- case IS_TRUE :
2667- case IS_FALSE :
2668- case IS_LONG :
2669- if (zend_string_equals_literal (str_idx , "read_and_close" )) {
2670- read_and_close = zval_get_long (value );
2661+ ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (options ), str_idx , value ) {
2662+ if (UNEXPECTED (!str_idx )) {
2663+ zend_argument_value_error (1 , "must be of type array with keys as string" );
2664+ RETURN_THROWS ();
2665+ }
2666+ switch (Z_TYPE_P (value )) {
2667+ case IS_STRING :
2668+ case IS_TRUE :
2669+ case IS_FALSE :
2670+ case IS_LONG :
2671+ if (zend_string_equals_literal (str_idx , "read_and_close" )) {
2672+ zend_long tmp ;
2673+ if (Z_TYPE_P (value ) != IS_STRING ) {
2674+ tmp = zval_get_long (value );
26712675 } else {
2672- zend_string * tmp_val ;
2673- zend_string * val = zval_get_tmp_string (value , & tmp_val );
2674- if (php_session_start_set_ini (str_idx , val ) == FAILURE ) {
2675- php_error_docref (NULL , E_WARNING , "Setting option \"%s\" failed" , ZSTR_VAL (str_idx ));
2676+ if (is_numeric_string (Z_STRVAL_P (value ), Z_STRLEN_P (value ), & tmp , NULL , false) != IS_LONG ) {
2677+ zend_type_error ("%s(): Option \"%s\" value must be of type compatible with int, \"%s\" given" ,
2678+ get_active_function_name (), ZSTR_VAL (str_idx ), Z_STRVAL_P (value )
2679+ );
2680+ RETURN_THROWS ();
26762681 }
2677- zend_tmp_string_release (tmp_val );
26782682 }
2679- break ;
2680- default :
2681- zend_type_error ("%s(): Option \"%s\" must be of type string|int|bool, %s given" ,
2683+ read_and_close = (tmp > 0 );
2684+ } else {
2685+ zend_string * tmp_val ;
2686+ zend_string * val = zval_get_tmp_string (value , & tmp_val );
2687+ if (php_session_start_set_ini (str_idx , val ) == FAILURE ) {
2688+ php_error_docref (NULL , E_WARNING , "Setting option \"%s\" failed" , ZSTR_VAL (str_idx ));
2689+ }
2690+ zend_tmp_string_release (tmp_val );
2691+ }
2692+ break ;
2693+ default :
2694+ zend_type_error ("%s(): Option \"%s\" must be of type string|int|bool, %s given" ,
26822695 get_active_function_name (), ZSTR_VAL (str_idx ), zend_zval_value_name (value )
2683- );
2684- RETURN_THROWS ();
2685- }
2696+ );
2697+ RETURN_THROWS ();
26862698 }
2687- (void ) num_idx ;
26882699 } ZEND_HASH_FOREACH_END ();
26892700 }
26902701
0 commit comments