Skip to content

Commit bace93f

Browse files
committed
Fix default value handling of session_set_cookie_params()
1 parent bd50198 commit bace93f

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

ext/session/session.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,10 @@ PHP_FUNCTION(session_set_cookie_params)
16901690
ZEND_PARSE_PARAMETERS_START(1, 5)
16911691
Z_PARAM_ARRAY_HT_OR_LONG(options_ht, lifetime_long)
16921692
Z_PARAM_OPTIONAL
1693-
Z_PARAM_STR(path)
1694-
Z_PARAM_STR(domain)
1695-
Z_PARAM_BOOL_EX(secure, secure_null, 1, 0)
1696-
Z_PARAM_BOOL_EX(httponly, httponly_null, 1, 0)
1693+
Z_PARAM_STR_OR_NULL(path)
1694+
Z_PARAM_STR_OR_NULL(domain)
1695+
Z_PARAM_BOOL_OR_NULL(secure, secure_null)
1696+
Z_PARAM_BOOL_OR_NULL(httponly, httponly_null)
16971697
ZEND_PARSE_PARAMETERS_END();
16981698

16991699
if (PS(session_status) == php_session_active) {
@@ -1711,12 +1711,23 @@ PHP_FUNCTION(session_set_cookie_params)
17111711
zval *value;
17121712

17131713
if (path) {
1714-
path = NULL;
1715-
domain = NULL;
1716-
secure_null = 1;
1717-
httponly_null = 1;
1718-
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
1719-
RETURN_FALSE;
1714+
zend_argument_value_error(2, "must be null when argument #1 ($lifetime_or_options) is an array");
1715+
RETURN_THROWS();
1716+
}
1717+
1718+
if (domain) {
1719+
zend_argument_value_error(3, "must be null when argument #1 ($lifetime_or_options) is an array");
1720+
RETURN_THROWS();
1721+
}
1722+
1723+
if (!secure_null) {
1724+
zend_argument_value_error(4, "must be null when argument #1 ($lifetime_or_options) is an array");
1725+
RETURN_THROWS();
1726+
}
1727+
1728+
if (!httponly_null) {
1729+
zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array");
1730+
RETURN_THROWS();
17201731
}
17211732

17221733
ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) {

ext/session/session.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function session_cache_limiter(?string $cache_limiter = null): string|false {}
4949

5050
function session_cache_expire(?int $new_cache_expire = null): int|false {}
5151

52-
function session_set_cookie_params(array|int $lifetime_or_options, string $path = UNKNOWN, string $domain = "", ?bool $secure = null, ?bool $httponly = null): bool {}
52+
function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {}
5353

5454
function session_start(array $options = []): bool {}
5555

ext/session/session_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: cf9ad3772fe851d2989d51338b316c53041da106 */
2+
* Stub hash: 9bdf602c14822b13553a5214a415e312c21cd30c */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
@@ -79,8 +79,8 @@ ZEND_END_ARG_INFO()
7979

8080
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_set_cookie_params, 0, 1, _IS_BOOL, 0)
8181
ZEND_ARG_TYPE_MASK(0, lifetime_or_options, MAY_BE_ARRAY|MAY_BE_LONG, NULL)
82-
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
83-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\"\"")
82+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 1, "null")
83+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 1, "null")
8484
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 1, "null")
8585
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, httponly, _IS_BOOL, 1, "null")
8686
ZEND_END_ARG_INFO()

ext/session/tests/session_set_cookie_params_variation7.phpt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ var_dump(session_set_cookie_params(["lifetime" => 42]));
4040
var_dump(ini_get("session.cookie_lifetime"));
4141

4242
var_dump(ini_get("session.cookie_path"));
43-
var_dump(session_set_cookie_params(["path" => "newpath/"], "arg after options array"));
43+
44+
try {
45+
session_set_cookie_params(["path" => "newpath/"], "arg after options array");
46+
} catch (ValueError $exception) {
47+
echo $exception->getMessage() . "\n";
48+
}
49+
4450
var_dump(ini_get("session.cookie_path"));
4551

4652
echo "Done";
@@ -63,8 +69,6 @@ string(1) "0"
6369
bool(true)
6470
string(2) "42"
6571
string(1) "/"
66-
67-
Warning: session_set_cookie_params(): Cannot pass arguments after the options array in %s on line %d
68-
bool(false)
72+
session_set_cookie_params(): Argument #2 ($path) must be null when argument #1 ($lifetime_or_options) is an array
6973
string(1) "/"
7074
Done

0 commit comments

Comments
 (0)