Issue Bug Closed

#93095Persistence Session->hasIdentifier() triggers PHP warning "Illegal offset type in isset or empty" when no instances of class has yet been loaded

Claus Due 12/17/20, 10:37 updated 03/28/25, 12:01

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

  1. Gerrit Code Review pushed patch set 1 for master to change 67174 status New Under Review <span data-processor="relativetime" data-value="2020-12-17T10:44:52+00:00" > 12/17/20, 10:44 </span>

  2. Claus Due commented <span data-processor="relativetime" data-value="2020-12-18T11:50:24+00:00" > 12/18/20, 11:50 </span>

    Disregard open merge request – the issue is still relevant, but requires a different solution. Either of:

    • Make argument types on Session->hasIdentifier strict, or
    • Throw specific exception if $identifier is non-scalar

    Would have yielded a more specific error message and prevented the warning.

  3. Georg Ringer commented and changed status Under Review Closed <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