Re: Common method names part 2
| From: | Mika Tuupola | Date: | Fri, 20 Sep 2002 17:54:45 +0000 |
| Subject: | Re: Common method names part 2 | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9264@lists.php.net to get a copy of this message | ||
On Fri, 20 Sep 2002, Alan Knowles wrote:
> Something I've been doing recently is prefixing any methods that are
> (or expect) to be called statically with 'static', eg.
> object::staticGet(), object::staticAutoLoad().. staticStart()
DB_storage seems to use create() too, which brings me a question.
How can the code below work? The object is created via:
$classname = get_class($this);
$obj = new $classname($table);
But $this is not defined if calling create() statically.
DB_Storage::create($foo, $bar)
won't work, but
$s = new DB_Storage();
$s->create($foo, $bar);
works. So create() method isn't actually static?
This brings me back to an old question. Is there a way for
a static method to know into which class it belongs to?
-cut-
/**
* Static method used to create new DB storage objects.
* @param $data assoc. array where the keys are the names
* of properties/columns
* @return object a new instance of DB_storage or a subclass of it
*/
function &create($table, &$data)
{
$classname = get_class($this);
$obj = new $classname($table);
reset($data);
while (list($name, $value) = each($data)) {
$obj->_properties[$name] = true;
$obj->$name = &$value;
}
return $obj;
}
-cut-
--
Mika Tuupola http://www.appelsiini.net/~tuupola/