1) A temporary fix for the recursion problem with the $GLOBALS array.
authorrobekras <robekras>
Tue, 18 Oct 2005 19:34:16 +0000 (19:34 +0000)
committerrobekras <robekras>
Tue, 18 Oct 2005 19:34:16 +0000 (19:34 +0000)
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java

index d0576f9..03a735f 100644 (file)
@@ -394,6 +394,43 @@ public class PHPDBGInterface {
        }
 
        /**
+        * Go up the tree of PHPVariables
+        * look whether the PHPValue is a reference to a parent PHPValue
+        *
+        * TODO Check where this recursion can come from.
+        * Whether this back reference is legal or a bug.
+        *
+        * @param var
+        * @return
+        * <ul>
+        * <li> false if the PHPValue is not a child of itself
+        * <li> true if the PHPValue is
+        * </ul>
+        */
+
+       private boolean hasRecursion (PHPVariable var) {
+               PHPVariable parentVar;
+               PHPValue    val;
+
+               val = (PHPValue) var.getValue ();                                                       // Get the PHPValue from the current PHPVariable
+
+               while (var != null) {                                                                           // As long as we have PHPVariable
+                       parentVar = var.getParent ();                                                   // Get the parent PHPVariable
+
+                       if (parentVar != null) {                                // Is there a parent?
+                               if (parentVar.getValue ().equals (val)) {                       // Get the PHPValue for the parent PHPVariable and check
+                                                                                                                                       // whether it is the same
+                                       return true;                                                                    // Return, if we have recursion
+                               }
+                       }
+
+                       var = parentVar;
+               }
+
+               return false;                                                                                           // No recursion found
+       }
+
+       /**
         * This method updates the 'static' variables list.
         * It does a replication between the 'static' list (the variable list which
         * is a member of this DBG interface object) and the DBG variable list
@@ -436,10 +473,13 @@ public class PHPDBGInterface {
                                        valNew = (PHPValue) varNew.getValue ();         // Get the value from DBG
 
                                        try {
-                                               if (valOld.hasVariables () ||                                   // If the 'static' value has child variables
-                                                   valNew.hasVariables ()) {                                                   //  or if the DBG value has child variables
-                                                       updateVariableList (valOld.getChildVariables (),        // Update the variable list for the child variables
-                                                                                               valNew.getChildVariables ());
+                                               if (valOld.hasVariables () ||                           // If the 'static' value has child variables
+                                                   valNew.hasVariables ()) {                           //  or if the DBG value has child variables
+                                                       if (!hasRecursion (varOld) &&
+                                                           !hasRecursion (varNew)) {                   // Both branches should not have a recursion
+                                                               updateVariableList (valOld.getChildVariables (),        // Update the variable list for the child variables
+                                                                                                       valNew.getChildVariables ());
+                                                       }
                                                }
                                                else if (!valOld.getValueString ().equals (valNew.getValueString ())) { // Has the value changed?
                                                        valOld.setValueString (valNew.getValueString ());                   // Yes, set the 'static' value (variable) to the new value
@@ -517,7 +557,7 @@ public class PHPDBGInterface {
                evalStr         = new PHPDBGEvalString (stack, serGlobals); // Process serialized variables
                updateVariableList (DBGVarList, evalStr.getVariables ());       // Replicate the 'static' variable list and the via DBG received variable list
 
-               return DBGVarList;                                                                                      // Convert the list to an array and return the array
+               return DBGVarList;                                                                                      // Return the variables as list
        }
 
        /**