61122[BUGFIX] Prevent PHP Warning with TCA selectTree
Commit message
Review
-
Code review CR +2 Done
- Anja Leichsenring +2
- Oliver Klee +1
- Tymoteusz Motylewski +1
-
Verified V +2 Done
- Anja Leichsenring +2
- Tymoteusz Motylewski +1
- TYPO3com +1 CI
Issues 1
Files 1
Review log 2427
Show 12 earlier messages
-
Markus Klein uploaded patch set 1 06/24/19, 16:45
-
TYPO3com voted on patch set 1 V +1 06/24/19, 16:57 Completed build in 11m 21s on Mon, 24 Jun, 06:57 PM Test Summary: 46478 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-34521
-
Joerg Kummer voted on patch set 1 CR +1 06/24/19, 17:01
-
Joerg Kummer commented on patch set 1 06/24/19, 17:23
I can't verify, cause i can't reproduce to get PHP warning (in v8.7 and master) -
Oliver Klee voted on patch set 1 CR +1 06/24/19, 18:42
-
Markus Klein commented on patch set 1 06/24/19, 19:10
@Jörg: I added a bit more information to forge which might be relevant to reproduce -
Alexander Schnitzler commented on patch set 1 CR -1 06/25/19, 13:31
TcaRecordTitle.php:237Please let's not introduce new empty checks and use a proper check here. What do you desire to check? The type, the length or both? What about this instead? if (count($fieldConfig['items'] ?? []) > 0) -
Alexander Schnitzler commented on patch set 1 06/25/19, 13:38
TcaRecordTitle.php:237ReplySorry, this doesn't check if the entry is an array. if (isset($fieldConfig['items']) && is_array($fieldConfig['items']) && count($fieldConfig['items']) > 0) This does only the necessary checks, returns early and is also more verbose than the empty check. -
Oliver Klee commented on patch set 1 06/25/19, 13:53
TcaRecordTitle.php:237ReplyThe count is not needed in that case as a foreach on an empty array is a no-op. -
Alexander Schnitzler commented on patch set 1 06/25/19, 14:01
TcaRecordTitle.php:237ReplyWell, you are right that the count check isn't necessary but not for the reason that there is a loop. $fieldConfig['items'] isn't used in a loop here but in the array_column call. We need to make sure that $fieldConfig['items'] is an array and empty would return true for non-empty strings here as well. And you can never trust user data. -
Oliver Klee commented on patch set 1 06/25/19, 14:03
TcaRecordTitle.php:237ReplyYou are right, and I think you have misunderstood me. :-) I'm fine with the isset and is_array. I only think that the count is not necessary. -
Alexander Schnitzler commented on patch set 1 06/25/19, 14:05
TcaRecordTitle.php:237ReplyNo no, I got you :) We remove the count and we're fine. -
Markus Klein commented on patch set 1 06/26/19, 19:17
TcaRecordTitle.php:237ReplyEmpty is just right here. We need to check emptiness and existence. It is IMO not necessary to check for array type here. Either we have a bug in Core if this is not an array (which is okay to trigger any sort of hard error then) or someone coded the items array in TCA manually and wrong (hard error okay too). So we can rely on being an array, if set. -
Alexander Schnitzler commented on patch set 1 06/27/19, 06:42
TcaRecordTitle.php:237ReplyIf $fieldConfig['items'] is an array, `empty()` checks just the right thing, true. But `empty()` itself is an anti pattern due to the fact that its exact functioning is dependent on the type it operates on. We can let `array_column` fail with a possible TypeError here, but we could also properly deal with the user input, detect a wrong configuration and act accordingly, like throwing an Exception that specifically tells the user what's wrong. However, my main issue is with `empty()` as this is a shorthand expression which equals `(!isset($v) || $v != true)` which is a non type-safe check. imo we should avoid empty in general and use type safe checks that are more verbose. -
Markus Klein commented on patch set 1 06/27/19, 06:47
TcaRecordTitle.php:237Reply UnresolvedWe obviously have a different take on empty(). IMO it's the best choice in most situations, simply because it internally is as fast as isset() due to being compiled to a single opcode - in contrast to the !isset($v) || !$v thingy. IMO we don't need a better error message than what PHP already delivers when items is not an array. It already tells us that it expects an array here. -
Markus Klein rebased onto patch set 2 07/21/19, 22:38
-
TYPO3com voted on patch set 2 V +1 07/21/19, 22:50 Completed build in 11m 54s on Mon, 22 Jul, 12:50 AM Test Summary: 47159 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35254
-
Andreas Kienast voted on patch set 2 V +1 CR +1 07/22/19, 06:57
-
Oliver Klee voted on patch set 2 CR +1 07/22/19, 14:56
-
Tymoteusz Motylewski commented on patch set 2 07/22/19, 19:41
TcaRecordTitle.php:239shouldn't the array_column($fieldConfig['items']) be taken outside the foreach loop? -
Markus Klein commented on patch set 3 07/22/19, 20:13
Published edit on patch set 2. -
Markus Klein commented on patch set 3 07/22/19, 20:14
TcaRecordTitle.php:239ReplyDone -
TYPO3com voted on patch set 3 V +1 07/22/19, 20:24 Completed build in 10m 58s on Mon, 22 Jul, 10:24 PM Test Summary: 47160 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35276
-
Oliver Klee voted on patch set 3 CR +1 07/22/19, 21:39
-
Tymoteusz Motylewski voted on patch set 3 V +1 CR +1 07/23/19, 05:56
-
Anja Leichsenring voted on patch set 3 V +2 CR +2 08/02/19, 13:27
-
Anja Leichsenring merged patch set 4 08/02/19, 13:27