Permalink
Browse files

Fix static variable caching of instances causing infinite nesting

in JForm, #1354
  • Loading branch information...
klas committed Jul 12, 2012
1 parent ec5b559 commit 993426dbf28aeaabacb5f3b877b54e87079d8483
Showing with 1 addition and 7 deletions.
  1. +1 −7 libraries/joomla/form/form.php
@@ -62,12 +62,6 @@ class JForm
*/
protected $xml;
- /**
- * Form instances.
- * @var array
- * @since 11.1
- */
- protected static $forms = array();
/**
* Method to instantiate the form object.
@@ -1962,7 +1956,7 @@ public static function addRulePath($new = null)
public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false)
{
// Reference to array with form instances
- $forms = &self::$forms;
+ static $forms = array();
// Only instantiate the form if it does not already exist.
if (!isset($forms[$name]))

2 comments on commit 993426d

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?

Owner

klas replied Jul 12, 2012

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

Please sign in to comment.