Re: Common method names part 2

From: Date: Fri, 20 Sep 2002 17:46:16 +0000
Subject: Re: Common method names part 2
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-9265@lists.php.net to get a copy of this message
Mika Tuupola wrote:
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? partly:
__CLASS__ is in 4.3, although this is the 'defined class', not the called class..... the later may be possible via the get_call_stack (or whatever its called in php5)
-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-


« previous php.pear.dev (#9265) next »