Skip to content

Loading…

Incorrect static variable caching of instances causing infinite nesting in JForm #1354

Closed
klas opened this Issue · 4 comments

3 participants

@klas

Debugger screenshot

Storing instances in static variable accesible from the whole class is causing infinite nesting as each new instance will already contain this variable. Solution is to store them in static variable with a method scope

@klas klas added a commit to klas/joomla-platform that referenced this issue
@klas klas Fix static variable caching of instances causing infinite nesting
in JForm, #1354
993426d
@realityking
Joomla! member

What app is that? Eclipse?

@klas

Yes, Eclipse.

@klas

After some thought - only proper solution is to remove all this inside class variable cachings and move them to a factory class. In second phase it would be probably wise to also move all instances creation methods to separate factory classes.

The easiest and short term solutin - add new generic / abstracted JFactory method that would take class name as a parameter and would take care about instances creation for all classes, for now just call classes existing getInstance methods and cache them in static variable array. Something like

class JFactory {
  static $instance = array();
 ...
 ...
  createInstance( $classname, $parameters)  {

    $instance[array($classname, parameters)] = $classname::getInstance($parameters);

  }
 ...
 ...
}

Final goal would be to have abstract JFactory and then implement separate factories for platform subsections (.e.g by current subfolders) with concrete methods for each class in folder, replacing current getInstance methods currently residing inside classes.

@dongilbert

Continue the conversation on the pull request here: #1355

@dongilbert dongilbert closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.