Bug #93095

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

Added by Claus Due 9 months ago. Updated 9 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2020-12-17
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.4
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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.

#1

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

#2

Updated by Claus Due 9 months ago

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.

Also available in: Atom PDF