Persistence Session->hasIdentifier() triggers PHP warning "Illegal offset type in isset or empty" when no instances of class has yet been loaded
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:
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.
$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.
Updated by Gerrit Code Review 9 months ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67174
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.