@@ -206,17 +206,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
206
206
return result ;
207
207
}
208
208
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 ) {
210
210
int found = 0 ;
211
211
zend_string * key ;
212
212
zval * value ;
213
213
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
-
220
214
ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (options ), key , value ) {
221
215
if (key ) {
222
216
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
249
243
if (found == 0 && zend_hash_num_elements (Z_ARRVAL_P (options )) > 0 ) {
250
244
php_error_docref (NULL , E_WARNING , "No valid options were found in the given array" );
251
245
}
252
-
253
- return 1 ;
254
246
}
255
247
256
248
/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure[, bool httponly]]]]]])
@@ -276,10 +268,11 @@ PHP_FUNCTION(setcookie)
276
268
277
269
if (expires_or_options ) {
278
270
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 ;
282
274
}
275
+ php_head_parse_cookie_options_array (expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite );
283
276
} else {
284
277
expires = zval_get_long (expires_or_options );
285
278
}
@@ -291,7 +284,6 @@ PHP_FUNCTION(setcookie)
291
284
RETVAL_FALSE ;
292
285
}
293
286
294
- cleanup :
295
287
if (expires_or_options && Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
296
288
if (path ) {
297
289
zend_string_release (path );
@@ -314,7 +306,7 @@ PHP_FUNCTION(setrawcookie)
314
306
zval * expires_or_options = NULL ;
315
307
zend_string * name , * value = NULL , * path = NULL , * domain = NULL , * samesite = NULL ;
316
308
zend_long expires = 0 ;
317
- zend_bool secure = 0 , httponly = 0 , options_array = 0 ;
309
+ zend_bool secure = 0 , httponly = 0 ;
318
310
319
311
ZEND_PARSE_PARAMETERS_START (1 , 7 )
320
312
Z_PARAM_STR (name )
@@ -329,11 +321,11 @@ PHP_FUNCTION(setrawcookie)
329
321
330
322
if (expires_or_options ) {
331
323
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 ;
336
327
}
328
+ php_head_parse_cookie_options_array (expires_or_options , & expires , & path , & domain , & secure , & httponly , & samesite );
337
329
} else {
338
330
expires = Z_LVAL_P (expires_or_options );
339
331
}
@@ -345,8 +337,7 @@ PHP_FUNCTION(setrawcookie)
345
337
RETVAL_FALSE ;
346
338
}
347
339
348
- cleanup :
349
- if (options_array ) {
340
+ if (expires_or_options && Z_TYPE_P (expires_or_options ) == IS_ARRAY ) {
350
341
if (path ) {
351
342
zend_string_release (path );
352
343
}
0 commit comments