Skip to content

Commit 03b0b8f

Browse files
author
Alex Negrila
committed
Fix PHP 8.4 deprecations for setting session.use_trans_sid and session.use_only_cookies
1 parent 2e8f686 commit 03b0b8f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Yii Framework 2 Change Log
77
- Enh #20309: Add custom attributes support to style tags (nzwz)
88
- Bug #20329: pgsql: Column Schema doesn't recognize PG type cast (arkhamvm)
99
- Bug #8298: Loading fixtures does not update table sequence for Postgresql database (mtangoo)
10+
- Bug #20347: Fix compatibility with PHP 8.4: remove usage of `session.use_trans_sid` and `session.use_only_cookies` (tehmaestro)
1011

1112

1213
2.0.52 February 13, 2025

framework/web/Session.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function getHasSessionId()
260260
$request = Yii::$app->getRequest();
261261
if (!empty($_COOKIE[$name]) && ini_get('session.use_cookies')) {
262262
$this->_hasSessionId = true;
263-
} elseif (!ini_get('session.use_only_cookies') && ini_get('session.use_trans_sid')) {
263+
} elseif (PHP_VERSION_ID < 80400 && !ini_get('session.use_only_cookies') && ini_get('session.use_trans_sid')) {
264264
$this->_hasSessionId = $request->get($name) != '';
265265
} else {
266266
$this->_hasSessionId = false;
@@ -439,7 +439,7 @@ public function getUseCookies()
439439
{
440440
if (ini_get('session.use_cookies') === '0') {
441441
return false;
442-
} elseif (ini_get('session.use_only_cookies') === '1') {
442+
} elseif (PHP_VERSION_ID >= 80400 || ini_get('session.use_only_cookies') === '1') {
443443
return true;
444444
}
445445

@@ -462,13 +462,19 @@ public function setUseCookies($value)
462462
$this->freeze();
463463
if ($value === false) {
464464
ini_set('session.use_cookies', '0');
465-
ini_set('session.use_only_cookies', '0');
465+
if (PHP_VERSION_ID < 80400) {
466+
ini_set('session.use_only_cookies', '0');
467+
}
466468
} elseif ($value === true) {
467469
ini_set('session.use_cookies', '1');
468-
ini_set('session.use_only_cookies', '1');
470+
if (PHP_VERSION_ID < 80400) {
471+
ini_set('session.use_only_cookies', '1');
472+
}
469473
} else {
470474
ini_set('session.use_cookies', '1');
471-
ini_set('session.use_only_cookies', '0');
475+
if (PHP_VERSION_ID < 80400) {
476+
ini_set('session.use_only_cookies', '0');
477+
}
472478
}
473479
$this->unfreeze();
474480
}
@@ -503,7 +509,10 @@ public function setGCProbability($value)
503509
*/
504510
public function getUseTransparentSessionID()
505511
{
506-
return ini_get('session.use_trans_sid') == 1;
512+
if (PHP_VERSION_ID < 80400) {
513+
return ini_get('session.use_trans_sid') == 1;
514+
}
515+
return false;
507516
}
508517

509518
/**
@@ -512,7 +521,9 @@ public function getUseTransparentSessionID()
512521
public function setUseTransparentSessionID($value)
513522
{
514523
$this->freeze();
515-
ini_set('session.use_trans_sid', $value ? '1' : '0');
524+
if (PHP_VERSION_ID < 80400) {
525+
ini_set('session.use_trans_sid', $value ? '1' : '0');
526+
}
516527
$this->unfreeze();
517528
}
518529

0 commit comments

Comments
 (0)