Review main Merged

46117[BUGFIX] Prevent PHP error in DatabaseTreeDataProvider

Wouter Wolters CR -1 V +2 Easy +4 −2 updated 01/24/16, 12:40

Commit message

Check if $records is not empty before using in the foreach loop.

Review

  • Code review CR -1
    • Frank Nägler +2
    • Oliver Klee -1
    • Richard Haeser +1
    • Andreas Kienast +1
    • Morton Jonuschat +1
  • Verified V +2
    • Frank Nägler +2
    • Andreas Kienast +1
    • Morton Jonuschat +1

Issues 1

Files 1

Review log 10

  1. Wouter Wolters uploaded patch set 1 01/20/16, 20:13

  2. Richard Haeser voted on patch set 1 CR +1 01/20/16, 21:02

  3. Andreas Kienast voted on patch set 1 CR +1 V +1 01/21/16, 09:58

  4. Oliver Klee commented on patch set 1 CR -1 01/21/16, 10:02

    DatabaseTreeDataProvider.php:457

    A foreach over an empty array will not raise a PHP error, but it will be just a no-op. So the check is at least misleading for readers of this code. Instead, we should check for !== null or !== false (depending on which values $records can have). Or we check for is_array.
  5. Morton Jonuschat commented on patch set 1 CR +1 V +1 01/21/16, 10:07

    DatabaseTreeDataProvider.php:457 Reply

    As exec_SELECTgetRows returns either NULL or an array the empty() check avoids the PHP warning and communicates the intent clearly enough (IMHO). That foreach on an empty array is a noop means that the code just returns a bit earlier.
  6. Frank Nägler commented on patch set 1 CR +2 V +2 01/23/16, 21:02

    The patch is valid, and as Morton said, the check is ok. We use this kind of check along the core multiple times. @Oliver: please re-think your vote, I would like to merge this bugfix before our next 7.6 release, thx
  7. Gerrit merged patch set 1 01/24/16, 11:36

  8. Sascha Egerer commented on patch set 2 01/24/16, 11:39

    DatabaseTreeDataProvider.php:457 Reply

    Why not simply cast the result of exec_SELECTgetRows to an array? That would result in an empty array and the !empty check is not required anymore
  9. Sascha Egerer commented on patch set 2 01/24/16, 11:40

    Sorry submitted the patch by an accident ;-) But coreteam is fine with the merge as it has a +2 anyway...
  10. Wouter Wolters commented on patch set 2 01/24/16, 12:40

    Cherry Picked This patchset was cherry picked to branch TYPO3_7-6 as commit 3f04f731613db4a8ae65abab63cdd5e664f2b99f