X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FSafe_DataObject.php;h=e926cb0d588375f5724855259b7c9ac2f46fd28a;hb=189d34173311828ccfe0aec5f381ad26887384ce;hp=021f7b50645ff4118571d3f6b4aa4b4c53eb9442;hpb=81b6b58e33f55054b7e5dd546f06dbdb5696ed92;p=quix0rs-gnu-social.git diff --git a/classes/Safe_DataObject.php b/classes/Safe_DataObject.php index 021f7b5064..e926cb0d58 100644 --- a/classes/Safe_DataObject.php +++ b/classes/Safe_DataObject.php @@ -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. * @@ -77,6 +96,30 @@ class Safe_DataObject extends DB_DataObject $this->_link_loaded = false; } + /** + * Magic function called when someone attempts to call a method + * that doesn't exist. DB_DataObject uses this to implement + * setters and getters for fields, but neglects to throw an error + * when you just misspell an actual method name. This leads to + * silent failures which can cause all kinds of havoc. + * + * @param string $method + * @param array $params + * @return mixed + * @throws Exception + */ + function __call($method, $params) + { + $return = null; + // Yes, that's _call with one underscore, which does the + // actual implementation. + if ($this->_call($method, $params, $return)) { + return $return; + } else { + throw new Exception('Call to undefined method ' . + get_class($this) . '::' . $method); + } + } /** * Work around memory-leak bugs...