Project

General

Profile

Actions

Bug #90992

closed

Fix programming error that only works for subtle reasons

Added by Volker Diels-Grabsch about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2020-04-09
Due date:
% Done:

100%

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

Description

While developing an extension I noticed a misleading error message in the DataMapper. Hunting it down showed a clear programming error in DataMapper::thawProperties(). That method contains a big switch over a string, where one case is a boolean instead of a string:

switch ($propertyType) {
   case 'integer':
   ...
   case is_subclass_of($propertyType, \DateTimeInterface::class):
       $propertyValue = $this->mapDateTime(
           ...
       );
       break;
   ...
}

This error has been introduced in commit aabe5f717.

Surprisingly, this code is not as broken as it seems. It does work, but only for subtle reasons:

It works because switch uses == instead of === for comparison, and because $propertyType true holds for almost all strings $propertyType. Exceptions, of course, are the values '', '0' and null. However, for those falsy values, the call to is_subclass_of(...) returns false as well, so the case comparison yields true and the mapDateTime(...) code is actually executed! Among others, this means that if the property type could not be identified, we get an error message regarding a failed DateTime conversion, instead of the proper error message generated by the mapObjectToClassProperty(...) call in the default case.

To complicate things, this bug has already been noticed in #89857, but has been "fixed" in 7ca1f49c9 by catching the case $propertyType = null immediately before the switch. The cases of other falsy values such as '' and '0' can still trigger the bug.

I propose to actually fix this programming error instead of adding more workarounds:

The default case already contains if statements for the more complex cases, and originally even handled the DateTime case (until changed by commit aabe5f717). So I propose to put the DateTime case back to its original position.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #89857: Insufficient case statement in Extbase DataMapperClosed2019-12-05

Actions
Related to TYPO3 Core - Feature #72053: Extbase: Support \DateTimeInterface instead of \DateTimeClosed2015-12-04

Actions
Actions #1

Updated by Volker Diels-Grabsch about 4 years ago

  • Related to Bug #89857: Insufficient case statement in Extbase DataMapper added
Actions #2

Updated by Volker Diels-Grabsch about 4 years ago

  • Description updated (diff)
Actions #3

Updated by Volker Diels-Grabsch about 4 years ago

  • Related to Feature #72053: Extbase: Support \DateTimeInterface instead of \DateTime added
Actions #4

Updated by Gerrit Code Review about 4 years 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/+/64113

Actions #5

Updated by Gerrit Code Review about 4 years ago

Patch set 2 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/+/64113

Actions #6

Updated by Gerrit Code Review about 4 years ago

Patch set 3 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/+/64113

Actions #7

Updated by Gerrit Code Review about 4 years ago

Patch set 4 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/+/64113

Actions #8

Updated by Volker Diels-Grabsch about 4 years ago

  • TYPO3 Version changed from 10 to 9
Actions #9

Updated by Gerrit Code Review about 4 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64132

Actions #10

Updated by Volker Diels-Grabsch about 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #11

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF