Re: [PHP] Retrieving values from array on a class

2006-10-15 Thread AR
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

I've rewritten my class as you told me:

--
 class returnConfigParams

 {

  private static $instance = NULL;

  var $a;
  var $b;
  var $c;
  var $d;

  private function __construct() {
  } 

  // function that get the database parameters from "properties.php"

public static function getInstance() {

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(){
 }  

}
--

and i'm calling it with

returnConfigParams::getInstance(); (probably wrongly)

The question is how to access the individual elements of the array.

Can someone help me please ?

Cheers,
AR

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

> Just like you'd access members of any other array.
> 
> $whatever = $params_file->getMySQLParams();
> print($whatever[0]);
> 
> This is a matter of basic rules of the language. Did you know
> most of the grammer is described in the manual?
Sure, i already tried that, but it doesn't works.
All i get is a blank page.

BTW, here is my class:

class returnConfigParams
 {

  var $a;
  var $b;
  var $c;
  var $d;


  function getMySQLParams()
   {
include($_SERVER['DOCUMENT_ROOT']."/properties.php");

$values = array(0 => $a, 1 => $b, 2 => $c, 3 => $d);

return($values);

  }

}

Cheers,
AR

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

>> I have this class named "returnConfigParams" that returns an array
>> called "$values" through a function called "getMySQLParams()".
>>
>> My question is how to retrieve the values of the array from the file
>> that calls the class.
>>
>> I have:
>>
>> $params_file = New returnConfigParams;
>> $params_file->getMySQLParams();
>> print($params_file[0]);
> 
> var_dump($params_file->getMySQLParams());
> 
> You said the method returns the data, right?
Yes, it returns an array called $values.
My problem is how to access the individual member of the array.

Thanks in advance.

Cheers,
AR

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

Sorry for the newbie question :(

I have this class named "returnConfigParams" that returns an array
called "$values" through a function called "getMySQLParams()".

My question is how to retrieve the values of the array from the file
that calls the class.

I have:

$params_file = New returnConfigParams;
$params_file->getMySQLParams();
print($params_file[0]);

but doesn't work :(

Help me please.

I'm stuck on this for two hours and didn't find nothing on Google that
could help me.

Cheers,
AR

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to effectuate translations

2006-09-29 Thread AR
Hi,

I'm coding this software that has several files for several languages,
so that users can chose the one that suits him.

My question is what is the best way to integrate this in the PHP code,
i. e., to make it work.

Any help would be appreciated.

Warm regards,
Augusto Reis

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php