As I add methods to various DB_DataObject classes, I lean towards
Class Example extends DB_DataObject {
function methodx() //start fresh
{
$newObject = DB_DataObject::factory($this->__table);
/* do stuff with $newObject */
}
rather than
function methodx() //use current instance
{
/* do stuff with $this */
}
I've realized I do this because I don't know how to determine the state of $this. The calling code might have done any of the following:
$e = DB_DataObject::factory('Example'); $e->get(16); $e->methodx();
$e = DB_DataObject::factory('Example'); $e->somekey=$value; $e->methodx();
$e = DB_DataObject::factory('Example'); $e->somekey=$value; $e->find(); $e->methodx();
How can I determine the state of "$this" when I get my hands on it?
Are there rules of thumb or design for using the current instance vs. creating a new instance of the class?