On Sunday 15 October 2006 03:19, AR wrote: > Hi, > > > If you have an array assigned to a variable, you access elements of it > > with []. > > > > $foo = array('a', 'b', 'c'); > > > > print $foo[0]; // gives 'a' > > > > $bar = array('a' => 'hello', 'b' => 'world'); > > > > print $foo['b']; // gives 'world' > > I know that. > > I had my class written as: > ---------------------------------------------------------------- > class returnConfigParams > > { > > var $a; > var $b; > var $c; > var $d; > > > // function that get the database parameters from "properties.php" > function getMySQLParams() > > { > > include($_SERVER['DOCUMENT_ROOT']."/properties.php"); > > $mysql_parameters = array(0 => $a, 1 => $b, 2 => $c, 3 => $d); > > return($mysql_parameters); > > } > > } > > ?> > ---------------------------------------------------------------- > > and i got the array values with: > $params_file = New returnConfigParams; > $params = $params_file->getMySQLParams(); > values were $params[0], etc... > everything was fine. > > > then, someone suggested i might write it like this, so i can call it > with returnConfigParams::getMySQLParams(); > > ---------------------------------------------------------------- > class returnConfigParams > > { > > private static $instance = NULL; > > private function __construct() { > } > > // function that get the database parameters from "properties.php" > public static function getMySQLParams() { > > if (!self::$instance) > { > /*** set this to the correct path and add some error checking ***/ > include($_SERVER['DOCUMENT_ROOT']."/properties.php"); > self::$instance = array($a, $b, $c, $d); > } > return self::$instance; > } > > private function __clone(){ > } > > } > > ?> > ---------------------------------------------------------------- > > This way i can't get the array elements. > I've tried > $params = returnConfigParams::getMySQLParams(); > but no good. > > And that's the story. > > Cheers, > AR What exactly does properties.php do/contain? You are aware that the $a, $b, $c, and $d you reference in both versions are not the properties of the object, but local variables, right? If you want the object properties, you need to use $this->a, $this->b, etc. I still think both methods are highly over-engineered, however. -- Larry Garfield AIM: LOLG42 larry@xxxxxxxxxxxxxxxx ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php