Re: question of Object

From: Date: Mon, 19 May 2003 23:22:41 +0000
Subject: Re: question of Object
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-148200@lists.php.net to get a copy of this message
Hi, At the moment we are already making agregation. But we are more looking into a solution that would enable us to keep the properties of that object trought all the other objects. Thanks Yann On Mon, 2003-05-19 at 12:53, Burhan Khalid wrote: > Hello Yann, > > Monday, May 19, 2003, 5:25:11 PM, you wrote: > > YL> Hi, i have a good question on objects. > > YL> I have the fallowing classes Page, Elements,Menu,Product , Var (containt > YL> the post, get, session...) , Db and Error > > YL> Page is created once, and i beleive that Db should be created once too. > YL> But at the moment it is created in every class that needs to execute a > YL> query. > > [ snip ] > > YL> So is there a way to do what i am looking for without using globals and > YL> having Db extend every class that do a connection to the Database ? > > Here is an example : > > class db { function init() { mysql_connect(....) } [..] } > > class myclass { > > var $db; > > /* ---- */ > > function init() { > > $this->db = new db(); > $this->db->init(); > ... > } > } > > A few things to note : > > Database connection handles are not passed in sessions, and neither > are references. So if you are wanting an object to persist across > sessions, on each page you will have to open a new connection to the > database. > > If you are confused as to what each object has in its variables, > you can use this snippet to see a listing of all object vars : > > $foo = new myclass(); > echo "<pre>"; print_r(get_object_vars($foo)); echo "</pre>"; > > -- > Best regards, > Burhan > phplist[at]meidomus[dot]com > >

« previous php.general (#148200) next »