Skip to content

Commit

Permalink
Fix static variable caching of instances causing infinite nesting
Browse files Browse the repository at this point in the history
in JForm, joomla#1354
  • Loading branch information
klas committed Jul 12, 2012
1 parent ec5b559 commit 993426d
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions libraries/joomla/form/form.php
Expand Up @@ -62,12 +62,6 @@ class JForm
*/ */
protected $xml; protected $xml;


/**
* Form instances.
* @var array
* @since 11.1
*/
protected static $forms = array();


/** /**
* Method to instantiate the form object. * Method to instantiate the form object.
Expand Down Expand Up @@ -1962,7 +1956,7 @@ public static function addRulePath($new = null)
public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false) public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false)
{ {
// Reference to array with form instances // Reference to array with form instances
$forms = &self::$forms; static $forms = array();


// Only instantiate the form if it does not already exist. // Only instantiate the form if it does not already exist.
if (!isset($forms[$name])) if (!isset($forms[$name]))
Expand Down

2 comments on commit 993426d

@realityking
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We moved all of those instance holding variables outside the method scope so classes overriding the getInstance() method still have access to it, nut sure if it's worth loosing that.

Also that code looks incorrect, aren't you resetting $forms to an empty array with each instance you create?

@klas
Copy link
Owner Author

@klas klas commented on 993426d Jul 12, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works the same as with class variables, they are initialized only once, see joomla#5 here http://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.static

Please sign in to comment.