#93095Persistence Session->hasIdentifier() triggers PHP warning "Illegal offset type in isset or empty" when no instances of class has yet been loaded
Description
When calling Session->hasIdentifier() with an identifier that does not exist (because no object of that class type has been fetched), the function will internally call:
return isset($this->identifierMap[$this->getClassIdentifier($className)][$identifier]);
However, $this->identifierMap[$this->getClassIdentifier($className)] will be NULL which means that PHP will attempt to check if `null[$identifier]` is set, which then triggers the warning.
Suggested fix:
$classIdentifier = $this->getClassIdentifier($className);
return isset($this->identifierMap[$classIdentifier], $this->identifierMap[$classIdentifier][$identifier]);
By passing two arguments to isset() the function will return false immediately if the first reference is not set, which in the described use case, it isn’t. This then prevents the second reference – which would cause the warning to be triggered – from being evaluated.
Reviews 1
History 23
-
Gerrit Code Review pushed patch set 1 for master to change 67174 status
NewUnder Review <span data-processor="relativetime" data-value="2020-12-17T10:44:52+00:00" > 12/17/20, 10:44 </span> -
Georg Ringer commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2025-03-28T12:01:58+00:00" > 03/28/25, 12:01 </span>argument types are now strict since #100068, closing
Disregard open merge request – the issue is still relevant, but requires a different solution. Either of:
Would have yielded a more specific error message and prevented the warning.