Hello.
I need my class to know my config settings. Basically I insert EVERY singele configuration variable somehow in EVERY class to make it work. Is their a OOP approach that is better? I heard the GLOBAL array is bad in OOP.
So far i have (very clumsy) done two things to pass configuration variables to my class:
Example 1
config.inc.php
$country_id=1;
country.php
<?php
class Country {
public function show_country($country_id) {
if($country_id==1) {
echo 'The country is USA';
}
}
}
?>
index.php
<?php
$output = new Country();
include('config.inc.php');
$output->show_country($country_id);
?>
Example 2
config.inc.php
define(COUNTRY_ID,'1');
country.php
<?php
class Country {
public function show_country($country_id) {
$country_id = COUNTRY_ID;
if($country_id==1) {
echo 'The country is USA';
}
}
}
?>
index.php
<?php
$output = new Country();
include('config.inc.php');
$output->show_country();
?>