NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing a method from one class in another

Mikko Rantalainen mikko.rantalainen at peda.net
Thu Jan 19 09:17:49 EST 2006


Randal Rust wrote:
> [...] I
> was writing....
> 
> $this->db->conn->Execute($sql)
> $this->db->connErrorMsg()
> 
> Instantiating the DB outside of the class, and then passing it as an
> argument allowed me to shorten things to...
> 
> $db->Execute($sql)
> $db->ErrorMsg()

Why not just do
$db =& $this->db->conn;
and then just proceed with the above? It's pretty close to the total 
length of adding $db as an function argument if you consider that 
caller must also type the code to pass the DB handle.

After saying that, yes, the singleton pattern sounds like a valid 
alternative.

-- 
Mikko



More information about the talk mailing list