@@ -2634,9 +2634,8 @@ PHP_FUNCTION(session_start)
2634
2634
{
2635
2635
zval * options = NULL ;
2636
2636
zval * value ;
2637
- zend_ulong num_idx ;
2638
2637
zend_string * str_idx ;
2639
- zend_long read_and_close = 0 ;
2638
+ bool read_and_close = false ;
2640
2639
2641
2640
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|a" , & options ) == FAILURE ) {
2642
2641
RETURN_THROWS ();
@@ -2659,32 +2658,44 @@ PHP_FUNCTION(session_start)
2659
2658
2660
2659
/* set options */
2661
2660
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 );
2671
2675
} 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 ();
2676
2681
}
2677
- zend_tmp_string_release (tmp_val );
2678
2682
}
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" ,
2682
2695
get_active_function_name (), ZSTR_VAL (str_idx ), zend_zval_value_name (value )
2683
- );
2684
- RETURN_THROWS ();
2685
- }
2696
+ );
2697
+ RETURN_THROWS ();
2686
2698
}
2687
- (void ) num_idx ;
2688
2699
} ZEND_HASH_FOREACH_END ();
2689
2700
}
2690
2701
0 commit comments