summaryrefslogtreecommitdiff
path: root/ext/session
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-09-14 11:59:32 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-09-14 11:59:32 +0200
commit46c0c82a0fdb877fc222a13bd92422e543b160c6 (patch)
treeb21003ade62d5f2b5d47edae7f145ce51f5e7294 /ext/session
parent1c81a3456372693dc4036fd7a3deb143cbb3aeef (diff)
downloadphp-git-46c0c82a0fdb877fc222a13bd92422e543b160c6.tar.gz
Declare array|int and object-of-class|int types in stubs
Closes GH-6081 Co-Authored-By: Nikita Popov <nikic@php.net>
Diffstat (limited to 'ext/session')
-rw-r--r--ext/session/session.c42
-rw-r--r--ext/session/session.stub.php3
-rw-r--r--ext/session/session_arginfo.h8
-rw-r--r--ext/session/tests/session_set_cookie_params_variation7.phpt12
4 files changed, 40 insertions, 25 deletions
diff --git a/ext/session/session.c b/ext/session/session.c
index 4f12e447ba..79b82f90f7 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -1674,7 +1674,8 @@ PHPAPI void session_adapt_url(const char *url, size_t url_len, char **new_url, s
Set session cookie parameters */
PHP_FUNCTION(session_set_cookie_params)
{
- zval *lifetime_or_options = NULL;
+ HashTable *options_ht;
+ zend_long lifetime_long;
zend_string *lifetime = NULL, *path = NULL, *domain = NULL, *samesite = NULL;
zend_bool secure = 0, secure_null = 1;
zend_bool httponly = 0, httponly_null = 1;
@@ -1687,12 +1688,12 @@ PHP_FUNCTION(session_set_cookie_params)
}
ZEND_PARSE_PARAMETERS_START(1, 5)
- Z_PARAM_ZVAL(lifetime_or_options)
+ Z_PARAM_ARRAY_HT_OR_LONG(options_ht, lifetime_long)
Z_PARAM_OPTIONAL
- Z_PARAM_STR(path)
- Z_PARAM_STR(domain)
- Z_PARAM_BOOL_EX(secure, secure_null, 1, 0)
- Z_PARAM_BOOL_EX(httponly, httponly_null, 1, 0)
+ Z_PARAM_STR_OR_NULL(path)
+ Z_PARAM_STR_OR_NULL(domain)
+ Z_PARAM_BOOL_OR_NULL(secure, secure_null)
+ Z_PARAM_BOOL_OR_NULL(httponly, httponly_null)
ZEND_PARSE_PARAMETERS_END();
if (PS(session_status) == php_session_active) {
@@ -1705,20 +1706,31 @@ PHP_FUNCTION(session_set_cookie_params)
RETURN_FALSE;
}
- if (Z_TYPE_P(lifetime_or_options) == IS_ARRAY) {
+ if (options_ht) {
zend_string *key;
zval *value;
if (path) {
- path = NULL;
- domain = NULL;
- secure_null = 1;
- httponly_null = 1;
- php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be null when argument #1 ($lifetime_or_options) is an array");
+ RETURN_THROWS();
+ }
+
+ if (domain) {
+ zend_argument_value_error(3, "must be null when argument #1 ($lifetime_or_options) is an array");
+ RETURN_THROWS();
+ }
+
+ if (!secure_null) {
+ zend_argument_value_error(4, "must be null when argument #1 ($lifetime_or_options) is an array");
+ RETURN_THROWS();
+ }
+
+ if (!httponly_null) {
+ zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array");
+ RETURN_THROWS();
}
- ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(lifetime_or_options), key, value) {
+ ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) {
if (key) {
ZVAL_DEREF(value);
if(!strcasecmp("lifetime", ZSTR_VAL(key))) {
@@ -1754,7 +1766,7 @@ PHP_FUNCTION(session_set_cookie_params)
RETURN_THROWS();
}
} else {
- lifetime = zval_get_string(lifetime_or_options);
+ lifetime = zend_long_to_str(lifetime_long);
}
/* Exception during string conversion */
diff --git a/ext/session/session.stub.php b/ext/session/session.stub.php
index b8f9f33eba..36a0b983b9 100644
--- a/ext/session/session.stub.php
+++ b/ext/session/session.stub.php
@@ -49,8 +49,7 @@ function session_cache_limiter(?string $cache_limiter = null): string|false {}
function session_cache_expire(?int $new_cache_expire = null): int|false {}
-/** @param int|array $lifetime_or_options */
-function session_set_cookie_params($lifetime_or_options, string $path = UNKNOWN, string $domain = "", ?bool $secure = null, ?bool $httponly = null): bool {}
+function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {}
function session_start(array $options = []): bool {}
diff --git a/ext/session/session_arginfo.h b/ext/session/session_arginfo.h
index c47dee6315..f29a0df86b 100644
--- a/ext/session/session_arginfo.h
+++ b/ext/session/session_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 22b829d3cdd092c393c924f323cd19bea1517579 */
+ * Stub hash: 9bdf602c14822b13553a5214a415e312c21cd30c */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
@@ -78,9 +78,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_cache_expire, 0, 0, MAY_
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_set_cookie_params, 0, 1, _IS_BOOL, 0)
- ZEND_ARG_INFO(0, lifetime_or_options)
- ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\"\"")
+ ZEND_ARG_TYPE_MASK(0, lifetime_or_options, MAY_BE_ARRAY|MAY_BE_LONG, NULL)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 1, "null")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, httponly, _IS_BOOL, 1, "null")
ZEND_END_ARG_INFO()
diff --git a/ext/session/tests/session_set_cookie_params_variation7.phpt b/ext/session/tests/session_set_cookie_params_variation7.phpt
index 25feabf1fd..cdc56554e3 100644
--- a/ext/session/tests/session_set_cookie_params_variation7.phpt
+++ b/ext/session/tests/session_set_cookie_params_variation7.phpt
@@ -40,7 +40,13 @@ var_dump(session_set_cookie_params(["lifetime" => 42]));
var_dump(ini_get("session.cookie_lifetime"));
var_dump(ini_get("session.cookie_path"));
-var_dump(session_set_cookie_params(["path" => "newpath/"], "arg after options array"));
+
+try {
+ session_set_cookie_params(["path" => "newpath/"], "arg after options array");
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
var_dump(ini_get("session.cookie_path"));
echo "Done";
@@ -63,8 +69,6 @@ string(1) "0"
bool(true)
string(2) "42"
string(1) "/"
-
-Warning: session_set_cookie_params(): Cannot pass arguments after the options array in %s on line %d
-bool(false)
+session_set_cookie_params(): Argument #2 ($path) must be null when argument #1 ($lifetime_or_options) is an array
string(1) "/"
Done