Skip to content

Commit 4f187b8

Browse files
committed
Make session_cache_expire() arg an integer
This is logically an integer, and the function also returns the old value as an integer. The fact that the integer needs to be converted to a string for the ini assignment is an implementation detail.
1 parent 4a4c68d commit 4f187b8

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

ext/session/session.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,30 +2344,31 @@ static PHP_FUNCTION(session_cache_limiter)
23442344
Return the current cache expire. If new_cache_expire is given, the current cache_expire is replaced with new_cache_expire */
23452345
static PHP_FUNCTION(session_cache_expire)
23462346
{
2347-
zval *expires = NULL;
2348-
zend_string *ini_name;
2347+
zend_long expires;
2348+
zend_bool expires_is_null = 1;
23492349

2350-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &expires) == FAILURE) {
2350+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &expires, &expires_is_null) == FAILURE) {
23512351
return;
23522352
}
23532353

2354-
if (expires && PS(session_status) == php_session_active) {
2354+
if (!expires_is_null && PS(session_status) == php_session_active) {
23552355
php_error_docref(NULL, E_WARNING, "Cannot change cache expire when session is active");
23562356
RETURN_LONG(PS(cache_expire));
23572357
}
23582358

2359-
if (expires && SG(headers_sent)) {
2359+
if (!expires_is_null && SG(headers_sent)) {
23602360
php_error_docref(NULL, E_WARNING, "Cannot change cache expire when headers already sent");
23612361
RETURN_FALSE;
23622362
}
23632363

23642364
RETVAL_LONG(PS(cache_expire));
23652365

2366-
if (expires) {
2367-
convert_to_string_ex(expires);
2368-
ini_name = zend_string_init("session.cache_expire", sizeof("session.cache_expire") - 1, 0);
2369-
zend_alter_ini_entry(ini_name, Z_STR_P(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
2366+
if (!expires_is_null) {
2367+
zend_string *ini_name = zend_string_init("session.cache_expire", sizeof("session.cache_expire") - 1, 0);
2368+
zend_string *ini_value = zend_long_to_str(expires);
2369+
zend_alter_ini_entry(ini_name, ini_value, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
23702370
zend_string_release_ex(ini_name, 0);
2371+
zend_string_release_ex(ini_value, 0);
23712372
}
23722373
}
23732374
/* }}} */

ext/session/tests/session_cache_expire_error.phpt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int(-10)
120120
int(%s)
121121

122122
-- Iteration 9 --
123-
int(1)
123+
int(0)
124124

125125
-- Iteration 10 --
126126
int(0)
@@ -141,22 +141,34 @@ int(0)
141141
int(1)
142142

143143
-- Iteration 16 --
144-
int(0)
144+
145+
Warning: session_cache_expire() expects parameter 1 to be int, string given in %s on line %d
146+
NULL
145147

146148
-- Iteration 17 --
147-
int(0)
149+
150+
Warning: session_cache_expire() expects parameter 1 to be int, string given in %s on line %d
151+
NULL
148152

149153
-- Iteration 18 --
150-
int(0)
154+
155+
Warning: session_cache_expire() expects parameter 1 to be int, string given in %s on line %d
156+
NULL
151157

152158
-- Iteration 19 --
153-
int(0)
159+
160+
Warning: session_cache_expire() expects parameter 1 to be int, string given in %s on line %d
161+
NULL
154162

155163
-- Iteration 20 --
156-
int(0)
164+
165+
Warning: session_cache_expire() expects parameter 1 to be int, string given in %s on line %d
166+
NULL
157167

158168
-- Iteration 21 --
159-
int(0)
169+
170+
Warning: session_cache_expire() expects parameter 1 to be int, object given in %s on line %d
171+
NULL
160172

161173
-- Iteration 22 --
162174
int(0)
@@ -165,5 +177,7 @@ int(0)
165177
int(0)
166178

167179
-- Iteration 24 --
168-
int(0)
180+
181+
Warning: session_cache_expire() expects parameter 1 to be int, resource given in %s on line %d
182+
NULL
169183
Done

0 commit comments

Comments
 (0)