Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Bug: Assigning null to ?array $identities property without proper handling

已关闭
#1,302 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@wakqasahmed 已经在做这个了。

开始于 2026年10月2日。

  • #1383 来自 @wakqasahmed —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
php

调研方向

从 src/Entities/User.php 开始,重点查看第 50 行附近的 nullable $identities 声明,以及第 130 行和第 149 行附近的赋值。重新加载所有 identity 以复现问题,然后检查引发 TypeError 的 setter 路径。当 identity 能够在不出现与 null 相关的错误的情况下重新加载时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug
PHP Version

8.2.7

CodeIgniter4 Version

4.6.3

Shield Version

1.2.0

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

mysqlite(memory unittest)

Did you customize Shield?

yes:

class User extends \CodeIgniter\Shield\Entities\User
.
.
.
public function saveUsernameIdentity(): bool
	{
		if (empty($this->username) && empty($this->password) && empty($this->password_hash)) {
			return true;
		}

		/** @var UserIdentityModel $identityModel */
		$identityModel = model(UserIdentityModel::class);

		$identity = $this->getIdentity('username_password');
		if ($identity === null && !empty($this->username)) {
			$this->identities = null;

			$this->createUsernameIdentity( [
				'username' => $this->username,
				'password' => '',
			]);


			$identity = $this->getUsernameIdentity();
		}

		if ($identity !== null) {
			if (!empty($this->username)) {
				$identity->secret = $this->username;
			}

			if (!empty($this->password)) {
				$identity->secret2 = service('passwords')->hash($this->password);
			}

			if (!empty($this->password_hash) && empty($this->password)) {
				$identity->secret2 = $this->password_hash;
			}

			try {
				$identityModel->save($identity);
			} catch (\CodeIgniter\Database\Exceptions\DataException $e) {
				$messages = [
					lang('Database.emptyDataset', ['insert']),
					lang('Database.emptyDataset', ['update']),
				];
				if (in_array($e->getMessage(), $messages, true)) {
					return true;
				}

				throw $e;
			}
		}

		return true;
	}
What happened?

the $identities property is correctly declared as nullable array:
https://github.com/codeigniter4/shield/blob/d07c0f9442dd0712b3fa39bfba677838ff1b8e26/src/Entities/User.php#L50

However, in several places, we directly assign null like these:

https://github.com/codeigniter4/shield/blob/d07c0f9442dd0712b3fa39bfba677838ff1b8e26/src/Entities/User.php#L130

https://github.com/codeigniter4/shield/blob/d07c0f9442dd0712b3fa39bfba677838ff1b8e26/src/Entities/User.php#L149

TypeError: CodeIgniter\Shield\Entities\User::setIdentities(): Argument 1 ($identities) must be of type array, null given,

Steps to Reproduce

try to reload all identities

Expected Output

reload identities without error

Anything else?

No response

主要语言
PHP
星标
426
派生
144
平均合并
3 天 14 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codeigniter4/shield 的其他 Issue

查看 codeigniter4/shield 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。