I have a website & need to use list of countries in multiple pages. On some pages I need to display the list & on some pages I need to populate a dropdown from that list. For this I am aware of following methods. Which one is better & why or is there any other preferable option. I read somewhere that using static keyword slows down the code and creating Object everytime also slows down the code as it allocates and consumes memory every time. So please put some light on what's the best way out.
Method A :
class Country
{
public static $CountryList = array('Country 1', 'Country 2', .....);
}
In my pages I will use it with :
$Countries = Country :: $CountryList;
Method B :
class Country
{
public $CountryList = array('Country 1', 'Country 2', .....);
}
In my pages I will use it with :
$Obj = new Country();
$CountryList = $Obj->CountryList;
Method C :
class Country
{
private $CountryList = array('Country 1', 'Country 2', .....);
public static function getList()
{
return $this->CountryList;
}
}
In my pages I will use it with :
$Obj = new Country();
$CountryList = $Obj->getList();