Review main Merged

19007[TASK] Use short version ?: in ternary operator (PHP 5.3+)

Stefan Neufeind CR +2 V +2 Hard +234 −232 updated 01/31/14, 03:52

Commit message

Shorten some constructs, make them easier to read
and less error-prone.

Review

  • Code review CR +2
    • Christian Kuhn +2
  • Verified V +2
    • Christian Kuhn +2

Issues 1

Files 100

Show 80 more files

Review log 49

Show 24 earlier messages
  1. Stefan Neufeind commented on patch set 1 05/27/13, 17:19

    This "cleanup"-ride through the core grew larger than expected. Somebody please have a look over the changes. There are cases where an isset(...) was replaced with the new operator. Those need to be looked at especially since using ?: actually makes the construct behave like using empty() (with all the associated potential problems). Some sysexts are also part of this patch which reside in their own git-repos. Those would of course need to be split out ...
  2. Stefan Neufeind uploaded patch set 2 05/27/13, 17:19

  3. Markus Klein commented on patch set 1 21 comments 05/27/13, 17:19

    I would prefer that you didn't submit this Ok, I took the time to review a couple of files and comment all issues. In general I'd like to point out the following result: $t = "00"; echo $t > 0 ? "1" : "0"; #0 echo $t == 0 ? "1" : "0"; #1 echo $t ? "1" : "0"; #1 Whereas: $t = "0"; echo $t > 0 ? "1" : "0"; #0 echo $t == 0 ? "1" : "0"; #1 echo $t ? "1" : "0"; #0
  4. Markus Klein commented on patch set 2 11 comments 05/27/13, 17:19

    I would prefer that you didn't submit this Partial review. Will continue
  5. Helmut Hummel commented on patch set 1 1 comment 05/27/13, 17:19

    I would prefer that you didn't submit this I agree with Tymek. It's fine for the places where the behavior is not changed, but I would also not touch the places where isset() empty() $foo > 0 or the like is used.
  6. Tymoteusz Motylewski commented on patch set 1 05/27/13, 17:19

    I would prefer that you didn't submit this This change simplifies code in many places, but I would rather make the change only when we are sure it doesn't change behavior. As it might provide a lot of edge case regressions. BTW, empty() behaves differently then boolean casting (like in if($x) ) see: http://php.net/manual/en/types.comparisons.php See inline comments for some examples

    class.t3lib_userauthgroup.php:560

    it's not the same "-1" is not > 0, but after casting to boolean (bool)"-1" === TRUE, so it changes behaviour.

    ConditionMatcher.php:244

    change of behaviour for $x=0; isset($x) will return TRUE, while $x ? will return FALSE
  7. Mr. Jenkins commented on patch set 1 05/27/13, 17:19

  8. Mr. Jenkins commented on patch set 2 05/27/13, 17:19

  9. Stefan Neufeind uploaded patch set 3 08/19/13, 22:42

  10. Mr. Jenkins commented on patch set 3 08/19/13, 22:44

  11. Stefan Neufeind commented on patch set 3 08/19/13, 22:44

    needed a complete rebase. did so. Took Markus comments into account which he gave for the first part. Please see again if these changes are okay. It might be that there are some more possible repleacements which I didn't find so far. If somebody sees a way to automatically (?) investigate that would be great. Else I'd say maybe let's review this first batch here first.
  12. Marcus Krause commented on patch set 3 08/20/13, 12:06

    I do not see any benefits in this change but a lot of places where these changes need to thoroughly tested (logic changes) to not introduce regressions. Is it worth it?
  13. Stefan Neufeind commented on patch set 3 08/20/13, 12:43

    The logic-changes are things that need to be reviewed and maybe excluded from the patch if unsure. However for cases like $password ? $password : $be_user_data['p assword'] I feel it's definitely worth (and we're not risking a thing) to use a ternary operator instead. THere are also cases where longer array-names with keys etc. are given so that the first and second part around the question-mark easily span a whole row ... let's make those cases more readable, please.
  14. Markus Klein commented on patch set 3 08/20/13, 16:50

    @Marcus: I didn't review the newest version of the patch yet, but it should NOT contain any logic changes.
  15. Wouter Wolters commented on patch set 3 08/20/13, 21:19

    IMO to risky and don't see the real benefit here. Only the code will get smaller. I will not vote this issue but also not downvote if others wanna take the risk.
  16. Chris topher updated the commit message in patch set 3 12/11/13, 19:38

  17. Mr. Jenkins commented on patch set 4 12/11/13, 19:53

  18. Stefan Neufeind commented on patch set 4 12/18/13, 11:59

    Would be great if oyu could please go through this (long but not difficult) changeset before too many merge-conflicts or such arise due to other changes.
  19. Helmut Hummel commented on patch set 4 12/18/13, 22:53

    Boy, this is a massive change. thanks for your work on that.

    CreatePagesWizardModuleFunctionController.php:86

    Removing isset() will raise notices
  20. Helmut Hummel commented on patch set 4 1 comment 12/18/13, 22:58

  21. Markus Klein commented on patch set 4 12/18/13, 23:01

    Ehmmm. No! ;-)

    BackendController.php:461

    Change of behaviour.

    EditDocumentController.php:1331

    Change of behaviour. $TSconfig['properties'][$table] = "0" would be FALSE.

    NewRecordController.php:447

    Wrong. Triggers Warning if some key is not set.

    PageLayoutController.php:612

    This is actually a bug. It must be strlen($cRow['header']) here, since "0" is a valid header of a content element.

    TableController.php:100

    Triggers warning if key not set.

    InlineElement.php:206

    wrong result if $liveVersionId == 0

    InlineElement.php:406

    warning

    InlineElement.php:1248

    Warning

    SuggestDefaultReceiver.php:173

    wrong

    SuggestDefaultReceiver.php:190

    Warning

    SuggestElement.php:92

    wrong

    TreeElement.php:185

    Parenthesis wrong.

    TreeElement.php:188

    (isset($PA['fieldConf']['config']['exclusiveKeys']) ? $PA['fieldConf']['config']['exclusiveKeys'] : '')

    ValueSlider.php:64

    Warning

    ValueSlider.php:65

    Warning

    ValueSlider.php:68

    isset()

    FlexFormsHelper.php:77

    Warning if 'meta' not set in array. (captured by empty)

    FlexFormsHelper.php:81

    Warning if 'meta' not set in array. (captured by empty)

    FlexFormsHelper.php:83

    Warning if 'meta' not set in array. (captured by empty)

    FlexFormsHelper.php:129

    Warning if 'meta' not set in array. (captured by empty)

    FormEngine.php:879

    Warning

    FormEngine.php:1229

    Actually this has to be !empty().

    FrontendBackendUserAuthentication.php:147

    Warning

    BaseScriptClass.php:278

    if $MS_value is '' this will change behaviour. Better: if (!is_null($MS_value)) { $MS_value = $this->MOD..... }

    AbstractRecordList.php:347

    Change of behaviour if $altId = '0'

    ElementBrowserRecordList.php:86

    cob if $altId = '0'

    DocumentTemplate.php:456

    Don't change that. $uid is forced to be a valid integer in the original condition

    BackendUtility.php:991

    keep empty please

    IconUtility.php:583

    keep isset

    BackendUserAuthentication.php:718

    keep the > 0

    TransientMemoryBackend.php:79

    keep isset
  22. Helmut Hummel commented on patch set 4 12/18/13, 23:06

    ClickMenu.php:714

    While this change is functionally equivalent, I ask myself if it wouldn't make sense to make these places notice free, instead which would require not to use the ternary operator but a construct like: isset($rec['_ORIG_uid']) ? $rec['_ORIG_uid'] : $rec['uid'];

    ClickMenu.php:714 Reply

    Hm, there is a case where this key is set but the value is NULL, '' or 0? Anyway, the question is: Do this change although we might change that back at a later point?
  23. Stefan Neufeind commented on patch set 4 12/18/13, 23:16

    ClickMenu.php:714 Reply

    I guess that's hard to decide for each case, especially with such a large patch. Have this change as a "functional equivalent" for now maybe and go through parts one-by-one later? If you feel like it, maybe someday start with one class and ask yourself questions like the above mentioned - I expect there are much more similar cases that turn up along the road ... It's imho just not realistic in one such bunch.
  24. Helmut Hummel commented on patch set 4 12/19/13, 18:17

    ClickMenu.php:714 Reply

    OK. Fine, go ahead. No objections...
  1. Stefan Neufeind commented on patch set 4 12/19/13, 18:46

    Finally an okay from Helmut for this "beast" (due to it's size). I'd appreciate if you guys could have another look at it and maybe get this out the door if approved. I hope we don't need further review-rounds with loosing all votes over and over again. (Thanks though for all the work/thoughts involved in this patch.)
  2. Xavier Perseguers commented on patch set 4 CR -1 12/19/13, 18:58

    A real beast :) I skipped commenting at a few place where exactly the same comment was needed right after. Not all my comments are the same but "same here" is always related to removing isset() and thus most probably introducing a possible PHP warning. I know that a few places would never introduce a PHP warning because of preconditions but at others places like $_POST[whatever], for sure it introduces a PHP warning so this is the reason for my -1. But very good job!

    DataHandler.php:1517

    you convert a isset(X) ? X : Y to X ?: Y so here you clearly introduce a possible PHP warning

    DataHandler.php:2308

    same here, i'd say, really not sure maxitems is always set

    DataHandler.php:3333

    same here

    HtmlParser.php:1077

    same here

    Locales.php:258

    same here

    Locales.php:272

    same here

    IntrospectionProcessor.php:56

    same here

    Rfc822AddressesParser.php:597

    this stinks to have isset($comments), please additionally make sure it is initialized to an empty array, then this construct will certainly go away by itself.

    PageRenderer.php:2149

    isset(X) ? X : Y not the same anymore => PHP warning

    Registry.php:63

    same here

    TaskTypeRegistry.php:54

    same here

    FrontendContentAdapterService.php:92

    same here

    ConfigurationForm.php:219

    same here

    GeneralUtility.php:91

    same here

    GeneralUtility.php:2396

    same here

    GeneralUtility.php:2931

    you change the behaviour of a public function, before, having $localLimit < 0 would trigger the use of maxFileSize

    RootlineUtility.php:220

    isset(X) ? X : Y => introduce PHP warning

    FileHandlingUtility.php:202

    same here

    TypoScriptFactory.php:328

    isset(X) ? X : Y => introduce PHP warning

    TypoScriptFactory.php:347

    same here

    TypoScriptFactory.php:359

    same here

    Request.php:192

    same here

    Request.php:208

    same here

    Request.php:224

    same here

    FilesContentObject.php:80

    same here

    TypoScriptFrontendController.php:3572

    isset(X) ? X : Y => introduce PHP warning

    TypoScriptFrontendController.php:3810

    same here

    PageGenerator.php:557

    same here

    ImportExport.php:1174

    same here

    ImportExport.php:1266

    same here

    ImportExport.php:1320

    same here

    IndexSearchRepository.php:127

    same here

    Indexer.php:302

    same here

    Indexer.php:615

    same here

    Indexer.php:1611

    it's probably better to trim but it's not the same, I guess it's fine anyway

    AbstractDatabaseRecordList.php:409

    isset(X) ? X : Y => introduce PHP warning

    AbstractDatabaseRecordList.php:411

    same here

    SessionStorage.php:56

    same here

    BrowseLinks.php:257

    same here

    BrowseLinks.php:269

    same here

    CustomAttributeController.php:78

    same here

    CustomAttributeController.php:81

    same here

    Acronym.php:129

    same here

    Plaintext.php:85

    same here

    RteHtmlAreaBase.php:458

    same here

    RteHtmlAreaBase.php:716

    same here

    SchedulerModuleController.php:1366

    same here

    SetupModuleController.php:446

    same here
  3. Helmut Hummel commented on patch set 4 12/19/13, 22:38

    Thanks Xavier for catching those issues. Of course adding potential notices to the code does not make sense and must be avoided with this change.
  4. Stefan Neufeind commented on patch set 4 CR -1 12/19/13, 22:48

    I'll go through and remove cases where we are not fully sure it still works identical.

    DataHandler.php:2368

    maybe also leave this in here as well? haven't looked what $newValue can actually become. But "0" is not accepted with the new variant, whereas strlen() would be >0 and $newValue accepted.
  5. Stefan Neufeind uploaded patch set 5 12/19/13, 23:48

  6. Stefan Neufeind commented on patch set 5 12/19/13, 23:50

    After discussion here, I now went through again and removed all parts which I guess we might (potentially) feel uneasy with, especially also the isset-parts mentioned. This work was done on the patch-file, applied, fixed parts where it didn't apply cleanly anymore *sigh* etc. Please look through again. If you find any change you feel uneasy with, just push a new version immediately. But I hope we're near a goal now.
  7. Mr. Jenkins commented on patch set 5 CR -1 V -1 12/20/13, 00:00

  8. Stefan Neufeind uploaded patch set 6 12/20/13, 00:02

  9. Mr. Jenkins commented on patch set 6 12/20/13, 00:15

  10. Stefan Neufeind commented on patch set 6 01/16/14, 23:04

    ping?
  11. Stefan Neufeind commented on patch set 6 01/24/14, 00:00

    Would be great if sombeody could take another look at it, and if need be, push a new version immediately if something is still wrong. Last I looked across it I had the feeling we limited the patch meanwhile to cases which are "safe" - but you always find small things the more often you look at it :-)
  12. Stefan Neufeind commented on patch set 6 01/30/14, 12:53

    ping?
  13. Anja Leichsenring uploaded patch set 7 01/30/14, 13:45

  14. Anja Leichsenring commented on patch set 7 V +1 CR +1 01/30/14, 13:54

    rebased, read and run tests, Backend is still working after random clicking. So fine with me.
  15. Mr. Jenkins commented on patch set 7 01/30/14, 13:59

  16. Jigal van Hemert commented on patch set 7 CR +2 01/30/14, 14:15

    No testing environment ready (almost up and running), so no vote by testing.
  17. Stefan Neufeind commented on patch set 7 CR +1 01/30/14, 15:23

    thanks for the help
  18. Christian Kuhn commented on patch set 7 CR -1 01/30/14, 22:26

    FrontendEditPanel.php:272

    unrelated change?
  19. Stefan Neufeind uploaded patch set 8 01/30/14, 22:36

  20. Christian Kuhn uploaded patch set 9 01/30/14, 22:36

  21. Christian Kuhn commented on patch set 9 V +1 CR +1 01/30/14, 22:38

    uploaded exact same patch twice in same minute ^^
  22. Christian Kuhn commented on patch set 9 V +2 CR +2 01/30/14, 22:39

    Enough votes, no change except the obvious hunk removed now, go for it.
  23. Christian Kuhn merged patch set 10 01/30/14, 22:39

  24. Mr. Jenkins commented on patch set 8 01/31/14, 03:40

  25. Mr. Jenkins commented on patch set 9 01/31/14, 03:52