Moving callback functions to classes

I'm currently thinking about moving callback functions (for events, pluginhooks, etc) to classes.

My current plugin layout

  • start.php
  • /lib/functions.php
  • /lib/hooks.php
  • /lib/events.php

All the callbacks for plugin hooks can be found in /lib/hooks.php and for events /lib/events.php all other helper functions for my plugin go into /lib/functions.php

This way i can seperate all the functions and know where to look if i need something. It also reduces the size of the individual files thus increasing code readablility.

My new way i want to implement is

  • start.php
  • /classes/<vendor>/<plugin>/EntityMenu.php (eg /classes/ColdTrick/BlogTools/EntityMenu.php)
  • /classes/<vendor>/<plugin>/Cron.php (eg /classes/ColdTrick/BlogTools/Cron.php)
  • etc


Including files costs time, so try to do this just in time to save on processing time. Also most of the functions in the old system aren't used on every page, but they still need to be parsed.

Doing things in classes may make it easier to test? I don't know this because my plugins don't have tests (yet).

Your thoughts

I would like to hears some views on this point, because it could help in performance/testability but maybe it could hurt in readability/complexity.

Pleae let me know