Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#1,302 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@wakqasahmed ci sta già lavorando.

Dal 2/10/2026.

  • #1383 di @wakqasahmed — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php

Direzione di ricerca

Inizia in src/Entities/User.php, in particolare con la dichiarazione nullable di $identities intorno alla riga 50 e con le assegnazioni intorno alle righe 130 e 149. Riproduci il problema ricaricando tutte le identità, quindi esamina il percorso del setter che genera il TypeError. Il lavoro è completato quando le identità vengono ricaricate senza l'errore relativo a null.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
PHP
Stelle
426
Fork
144
Merge medio
3g 14h
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codeigniter4/shield

Tutte le issue di codeigniter4/shield

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.