From 33ed3218bf25a239f6c5a89e4312766141b158d5 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Mon, 29 Sep 2025 19:31:21 -0300 Subject: [PATCH] Fix #20548: Fix PHP `8.5` `null` array offset deprecation warnings --- framework/CHANGELOG.md | 1 + framework/db/BaseActiveRecord.php | 3 ++- framework/rbac/PhpManager.php | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 28d7d76de5..eabdc114e4 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -37,6 +37,7 @@ Yii Framework 2 Change Log - Bug #19655: Fix `LinkPager::getPageRange` when `maxButtons` is 2 (max-s-lab) - Enh #20539: Update minimum PHP version requirement from `7.3` to `7.4` (terabytesoftw) - Bug #20541: Remove deprecated caching components: `XCache` and `ZendDataCache`, and update related tests and documentation (terabytesoftw) +- Bug #20548: Fix PHP `8.5` `null` array offset deprecation warnings (terabytesoftw) - Enh #19526: Add the `convertIniSizeToBytes` method to `BaseStringHelper` (max-s-lab) diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index dfc7014080..05e2bb5727 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -835,7 +835,8 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface throw new StaleObjectException('The object being updated is outdated.'); } - if (isset($values[$lock])) { + // using null as an array offset is deprecated in PHP `8.5` + if ($lock !== null && isset($values[$lock])) { $this->$lock = $values[$lock]; } diff --git a/framework/rbac/PhpManager.php b/framework/rbac/PhpManager.php index e09d23c15a..9ab385d7f4 100644 --- a/framework/rbac/PhpManager.php +++ b/framework/rbac/PhpManager.php @@ -112,7 +112,12 @@ class PhpManager extends BaseManager */ public function getAssignments($userId) { - return isset($this->assignments[$userId]) ? $this->assignments[$userId] : []; + // using null as an array offset is deprecated in PHP `8.5` + if ($userId !== null && isset($this->assignments[$userId])) { + return $this->assignments[$userId]; + } + + return []; } /**