Skip to content

Commit a2d7665

Browse files
author
Yasuo Ohgaki
committed
Fixed bug #74514 5 session functions incorrectly warn when calling in read-only/getter mode
1 parent 66e5dc5 commit a2d7665

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
- SPL:
2020
. Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr)
2121

22+
- Session:
23+
. Fixed bug #74514 (5 session functions incorrectly warn when calling in
24+
read-only/getter mode). (Yasuo)
25+
2226
- Standard:
2327
. Add support for extension name as argument to dl().
2428
(francois at tekwire dot net)

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ PHP 7.2 UPGRADE NOTES
8686
session_start()
8787
. Session no longer initialize $_SESSION for invalid and useless session.
8888
session_start()
89+
. When headers are already sent and try to set new INI values, session_name(),
90+
session_module_name(), session_save_path(), session_cache_limiter() and
91+
session_cache_expire() are no longer works. Older PHPs accepts new values even
92+
if new values will not be effective.
93+
This new corrected behavior may affect command line mode CLI scripts that manage
94+
sessions. Use output buffer just like web applications to resolve problems on
95+
CLI scripts.
8996

9097

9198
========================================

ext/session/session.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ static PHP_FUNCTION(session_name)
17621762
RETURN_FALSE;
17631763
}
17641764

1765-
if (SG(headers_sent)) {
1765+
if (name && SG(headers_sent)) {
17661766
php_error_docref(NULL, E_WARNING, "Cannot change session name when headers already sent");
17671767
RETURN_FALSE;
17681768
}
@@ -1793,7 +1793,7 @@ static PHP_FUNCTION(session_module_name)
17931793
RETURN_FALSE;
17941794
}
17951795

1796-
if (SG(headers_sent)) {
1796+
if (name && SG(headers_sent)) {
17971797
php_error_docref(NULL, E_WARNING, "Cannot change save handler module when headers already sent");
17981798
RETURN_FALSE;
17991799
}
@@ -2004,7 +2004,7 @@ static PHP_FUNCTION(session_save_path)
20042004
RETURN_FALSE;
20052005
}
20062006

2007-
if (SG(headers_sent)) {
2007+
if (name && SG(headers_sent)) {
20082008
php_error_docref(NULL, E_WARNING, "Cannot change save path when headers already sent");
20092009
RETURN_FALSE;
20102010
}
@@ -2232,7 +2232,7 @@ static PHP_FUNCTION(session_cache_limiter)
22322232
RETURN_FALSE;
22332233
}
22342234

2235-
if (SG(headers_sent)) {
2235+
if (limiter && SG(headers_sent)) {
22362236
php_error_docref(NULL, E_WARNING, "Cannot change cache limiter when headers already sent");
22372237
RETURN_FALSE;
22382238
}
@@ -2263,7 +2263,7 @@ static PHP_FUNCTION(session_cache_expire)
22632263
RETURN_LONG(PS(cache_expire));
22642264
}
22652265

2266-
if (SG(headers_sent)) {
2266+
if (expires && SG(headers_sent)) {
22672267
php_error_docref(NULL, E_WARNING, "Cannot change cache expire when headers already sent");
22682268
RETURN_FALSE;
22692269
}

ext/session/tests/bug74514.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #74514 5 session functions incorrectly warn when calling in read-only/getter mode.
3+
--SKIPIF--
4+
<?php
5+
include('skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
/*
10+
CLI ignores HTTP headers at all, i.e. does not output any HTTP headers,
11+
but it still uses SG(headers_sent).
12+
13+
CLI works as Web server, so SG(headers_sent) cannot be ignored nor changed.
14+
Therefore, once HTTP header is considered as sent, these functions emits
15+
'headers already sent' errors if they try to set new values.
16+
17+
Older PHPs(<7.2) did not care about this misuse on Web SAPI.
18+
*/
19+
var_dump(session_name('foo'));
20+
var_dump(session_name());
21+
var_dump(session_module_name());
22+
var_dump(session_save_path());
23+
var_dump(session_cache_limiter());
24+
var_dump(session_cache_expire());
25+
?>
26+
===DONE===
27+
--EXPECT--
28+
string(9) "PHPSESSID"
29+
string(3) "foo"
30+
string(5) "files"
31+
string(0) ""
32+
string(7) "nocache"
33+
int(180)
34+
===DONE===

0 commit comments

Comments
 (0)