--- In php-list@yahoogroups.com, Wade Smart <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] wrote: > > Hi all, > > I am playing with classes for the first time and I am at a bit of a > > loss in php. > > > > How do I access the properties/functions of the parent class from sub > > function? > > > > And how do I register resources into the scope of the parent class? > > > > For example if I have - > > class Data_Base > > { > > var $server; > > var $username; > > var $password; > > function Data_Base > > { > > $this->server = "127.0.01"; > > $this->username = "username"; > > $this->password = "password"; > > } > > function Connect > > { > > $handle = mysql_connect($server, $username, $password); > > } > > } > > > > How do I get $server etc from the root scope of Data_Base? > > > > And how do I register $handle into the global scope of Data_Base without > > registering it into the global scope of PHP? > > > > ie - does var $server create a scope that is accessible in sub functions or > > is it just in the root scope? > > > > Thanks, Robert. > > 20081007 1639 GMT-6 > > Im just starting with objects myself so this might not be right. > But from the reading I was doing today, if you want the $handle you > would do "return $handle" just like a normal function. > > Wade >
Well, the scope of the $server, $username, $password variables is the class. You can only use these variables in the class 'calling' them with the $this->server. So, your connect won't work since it doesn't call the variables with $this. The $handle is available only for that method (function). If you want to use it, as wade said, use return.