]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Safe_DataObject.php
Drop result ID from data objects on clone(). This keeps the original object working...
[quix0rs-gnu-social.git] / classes / Safe_DataObject.php
index 021f7b50645ff4118571d3f6b4aa4b4c53eb9442..08bc6846f47bb905ac3893562ee7c5667fb51696 100644 (file)
@@ -42,6 +42,25 @@ class Safe_DataObject extends DB_DataObject
         }
     }
 
+    /**
+     * Magic function called at clone() time.
+     *
+     * We use this to drop connection with some global resources.
+     * This supports the fairly common pattern where individual
+     * items being read in a loop via a single object are cloned
+     * for individual processing, then fall out of scope when the
+     * loop comes around again.
+     *
+     * As that triggers the destructor, we want to make sure that
+     * the original object doesn't have its database result killed.
+     * It will still be freed properly when the original object
+     * gets destroyed.
+     */
+    function __clone()
+    {
+        $this->_DB_resultid = false;
+    }
+
     /**
      * Magic function called at serialize() time.
      *