@@ -206,17 +206,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
206206 return result ;
207207}
208208
209- static int php_head_parse_cookie_options_array (zval * options , zend_long * expires , zend_string * * path , zend_string * * domain , zend_bool * secure , zend_bool * httponly , zend_string * * samesite ) {
209+ static void php_head_parse_cookie_options_array (zval * options , zend_long * expires , zend_string * * path , zend_string * * domain , zend_bool * secure , zend_bool * httponly , zend_string * * samesite ) {
210210 int found = 0 ;
211211 zend_string * key ;
212212 zval * value ;
213213
214- if (* path ) {
215- * path = NULL ;
216- php_error_docref (NULL , E_WARNING , "Cannot pass arguments after the options array" );
217- return 0 ;
218- }
219-
220214 ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (options ), key , value ) {
221215 if (key ) {
222216 if (zend_string_equals_literal_ci (key , "expires" )) {
@@ -249,8 +243,6 @@ static int php_head_parse_cookie_options_array(zval *options, zend_long *expires
249243 if (found == 0 && zend_hash_num_elements (Z_ARRVAL_P (options )) > 0 ) {
250244 php_error_docref (NULL , E_WARNING , "No valid options were found in the given array" );
251245 }
252-
253- return 1 ;
254246}
255247
256248/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure[, bool httponly]]]]]])
@@ -276,10 +268,11 @@ PHP_FUNCTION(setcookie)
276268
277269 if (expires_or_options ) {
278270 if (Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
279- if (! php_head_parse_cookie_options_array ( expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite )) {
280- RETVAL_FALSE ;
281- goto cleanup ;
271+ if (UNEXPECTED ( ZEND_NUM_ARGS () > 3 )) {
272+ php_error_docref ( NULL , E_WARNING , "Cannot pass arguments after the options array" ) ;
273+ RETURN_FALSE ;
282274 }
275+ php_head_parse_cookie_options_array (expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite );
283276 } else {
284277 expires = zval_get_long (expires_or_options );
285278 }
@@ -291,7 +284,6 @@ PHP_FUNCTION(setcookie)
291284 RETVAL_FALSE ;
292285 }
293286
294- cleanup :
295287 if (expires_or_options && Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
296288 if (path ) {
297289 zend_string_release (path );
@@ -314,7 +306,7 @@ PHP_FUNCTION(setrawcookie)
314306 zval * expires_or_options = NULL ;
315307 zend_string * name , * value = NULL , * path = NULL , * domain = NULL , * samesite = NULL ;
316308 zend_long expires = 0 ;
317- zend_bool secure = 0 , httponly = 0 , options_array = 0 ;
309+ zend_bool secure = 0 , httponly = 0 ;
318310
319311 ZEND_PARSE_PARAMETERS_START (1 , 7 )
320312 Z_PARAM_STR (name )
@@ -329,11 +321,11 @@ PHP_FUNCTION(setrawcookie)
329321
330322 if (expires_or_options ) {
331323 if (Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
332- options_array = 1 ;
333- if (!php_head_parse_cookie_options_array (expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite )) {
334- RETVAL_FALSE ;
335- goto cleanup ;
324+ if (UNEXPECTED (ZEND_NUM_ARGS () > 3 )) {
325+ php_error_docref (NULL , E_WARNING , "Cannot pass arguments after the options array" );
326+ RETURN_FALSE ;
336327 }
328+ php_head_parse_cookie_options_array (expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite );
337329 } else {
338330 expires = Z_LVAL_P (expires_or_options );
339331 }
@@ -345,8 +337,7 @@ PHP_FUNCTION(setrawcookie)
345337 RETVAL_FALSE ;
346338 }
347339
348- cleanup :
349- if (options_array ) {
340+ if (expires_or_options && Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
350341 if (path ) {
351342 zend_string_release (path );
352343 }
0 commit comments