Classes got initialised regardless if it is needed or not

Issue #39 resolved
Jamin Xu created an issue

In mvc_admin_parent_factory.class.php, the following code initialise every class regardless if it is needed or not.

if ( $reflection->isSubclassOf( 'MVC_Admin_General' ) && $cla_str != $class ) {
// if extended by the general class and not the main one, run the class with init
   new $class();
}

Suggestion: Add an Constant like INIT_ME to the class which requires initialisation, and then we can run the following code to initialise the class

if ( defined( $class . '::INIT_ME' ) ) {
  new $class();
}

Comments (2)

  1. Jamin Xu reporter

    @Andrew Palfrey@Luke Nelson@dhodgkiss0@gmail.com

    I was thinking about this on my way home. I think we need a discussion to solve this problem. We now have three solutions:

    1. Use the 'admin_parent_factory_init_classes_fn' filter with the variable $initCla_arr, only items in $initCla_arr will be initialised. This is the original way but not in action anymore.
    2. Check if the class implements the interface class, if yes, initialise it.
    3. Add a constant like INIT_ME to the class which requires initialisation, and then we can check its existence to initialise the class.

    I think the third one is the simplest way because what needed to be done is just creating a constant, no need to put effort into implementing the Interface class or find a place to apply the filter. It is easier for our users to understand and apply as well.

    This is impacting our existing code and the future efficiency of coding. Could I have everyone’s opinions?

    If the explanation is not clear, we can have a meeting next week.

    Thanks

    Jamin

  2. Log in to comment