|
Posted by nephish on 10/07/43 11:57
Slant wrote:
> Hey nephish,
>
> You have some very good questions. I recently had some of these as
> well.
>
>
> > class MyClass
> > {
> > var $start;
> > var $finish;
>
> You don't HAVE to declair these variables here. It's just good
> practice to do so as you can change the scope of the variables here.
>
> > function MyClass($start, $finish)
>
> If you're using PHP 5, I'd HIGHLY recommend that you use the following
> instead of what you are using here:
>
> function __construct($start,$finish)
>
> Why? Because the method of building a construct using the same name as
> the class itself it old-school PHP 4 stuff. If you're still using PHP
> 4, then by all means, keep at it. The "__construct" method is the new
> method for PHP 5. Just cleans things up a bit! Give it a try. :)
>
> > {
> > $this->start = $start;
> > $this->finish=$finish,
> > $this->sensor_array = get_sensor_array();
> > }
>
> I see no reason why this should not work. In a recent post here in
> this same group, I posted a very similar example for a Database
> instantiation class:
>
> function __construct() {
>
> $db['host'] = "localhost";
> $db['user'] = "root";
> $db['pass'] = "";
> $db['name'] = "pbtportal";
>
> $link = mysql_connect($db['host'],$db['user'],$db['pass']);
> mysql_select_db($db['name'],$link);
>
> }
>
> Works like a charm! In this case, I did not declair the variable "$db"
> but probably should have.
>
> > function get_sensor_array
> > {
> > so some stuff to populate $this->sensor_array;
> > return array($this->sensor_array);
> > }
> > }
>
> I hope that helps!
Yes, this helps!
thanks very much for your reply.
i am testing code on a system with php5 and the production machine is
php4. I know this is not the best idea, but it's what i have.
i am using something similar to your code to have my user name and
password out of the web folder. It just hasn't been in a class. cool.
thanks again.
sk
Navigation:
[Reply to this message]
|