You are here: Re: can i have an array as a class variable? « PHP Programming Language « IT news, forums, messages
Re: can i have an array as a class variable?

Posted by Slant on 10/15/51 11:57

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!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация