Review main Merged

24277[TASK] Don't use destructor as shutdown function

Thorsten Kahler CR +2 V +2 Easy +9 −5 updated 11/10/13, 11:40

Commit message

GeneralUtility::makeInstanceService() registers service classes'
destructors as shutdown functions. This has two drawbacks:
* destructors are called twice usually
* service classes need to have destructors

The shutdown function for temp file cleanup in AbstractService is
registered on demand instead.

Review

  • Code review CR +2
    • Markus Klein +2
    • Sascha Egerer +1
  • Verified V +2
    • Markus Klein +2
    • Sascha Egerer +1

Issues 1

Files 2

Review log 21

  1. Thorsten Kahler commented on patch set 1 10/02/13, 16:32

    TODO: Update documentation in Typo3Services.git
  2. Markus Klein commented on patch set 1 CR -1 10/02/13, 16:36

    Releases line and Resolves line missing! Did you use the commit message hook linked in the wiki? It should tell on commit, that this is incorrect
  3. Mr. Jenkins commented on patch set 1 10/02/13, 16:45

  4. Thorsten Kahler uploaded patch set 2 10/03/13, 18:41

  5. Thorsten Kahler commented on patch set 2 10/03/13, 18:42

    Fixed commit message.
  6. Mr. Jenkins commented on patch set 2 10/03/13, 18:52

  7. Markus Klein voted on patch set 2 CR +1 10/03/13, 21:22

  8. Sascha Egerer commented on patch set 2 10/04/13, 05:42

    AbstractService.php:93

    A description would be nice
  9. Thorsten Kahler uploaded patch set 3 10/04/13, 06:19

  10. Thorsten Kahler commented on patch set 2 10/04/13, 06:20

    Added description for new class attribute $shutdownRegistry

    AbstractService.php:93 Reply

    Done
  11. Sascha Egerer voted on patch set 3 V +1 CR +1 10/04/13, 06:28

  12. Mr. Jenkins commented on patch set 3 10/04/13, 06:30

  13. Philipp Gampe voted on patch set 3 CR +1 10/04/13, 15:50

  14. Philipp Gampe commented on patch set 3 10/04/13, 16:00

    AbstractService.php:406

    this looks strange, you register "registerTempFile" = TRUE in the shutdownRegistry instead of the expected "unlinkTempFiles". Do we even need the registry? This is local to the service anyway and the author of a service should know when and how often to register functions as shutdown functions. This looks more like a hack, because someone does not understand OOP. The shutdown code should be moved to the destructor which needs to be called explicitly from the child class if it wants to make use of it in an own destructor. Otherwise it will be called automatically by PHP (if the child does not have an own destructor).
  15. Philipp Gampe voted on patch set 3 CR 0 10/04/13, 16:01

  16. Christian Kuhn commented on patch set 3 10/06/13, 20:55

    AbstractService.php:406 Reply

    I on't understand this call, too. @Thorsten: could you elaborate a bit?
  17. Markus Klein commented on patch set 3 10/07/13, 05:40

    AbstractService.php:406 Reply

    This is just a way of registering the function only once. The inheriting classes shall use this registry too to avoid double registration of their shutdown functions. I'd suggest to introduce a new API function to to this and make the $shutdownRegistry private
  18. Thorsten Kahler commented on patch set 3 10/07/13, 08:34

    AbstractService.php:406 Reply

    Yes, that was the intention. I'd seen three ways to prevent registering the same method more the once and decided on the middle path: - static variable: breaks with multiple instances of the class - class variable: might be used wrong - encapsulating in new method: looks like overhead for the rare case of (catchable) fatal errors Because we can safely assume that instances of this (abstract!) classes subclasses are singletons I now think that using a static variable would be sufficient.

    AbstractService.php:406 Reply

    The destructor was registered as shutdown function in the original code to emulate PHP5's behavior in PHP4. The effect is that the destructor is called twice in PHP5. Because we require PHP 5.2 since some versions it's now time to drop that compatibility code. The less obvious side effect of the old code is that shutdown functions are called even if a fatal error occurs. Cleaning up leftovers in the file system in such a case might not be a bad idea. Nevertheless the attribute comment doesn't match its usage, indeed.
  19. Thorsten Kahler commented on patch set 3 10/07/13, 08:41

    The more general question is: Do we need to take care of files in typo3temp in case of a PHP crash? IMO these can be deleted at any time, e.g. during "regular" website maintenance.
  20. Markus Klein commented on patch set 3 V +2 CR +2 11/10/13, 11:40

    Since the usage is clear now and there are no further responses, I'm merging this now.
  21. Markus Klein merged patch set 4 11/10/13, 11:40