ThomasJSmart
Programmer
- Sep 16, 2002
- 634
Just wondering if there would be anything against using a trait to store configuration settings for an application?
And secondly, was wondering if there was a way to only let specific classes call specific functions in a trait.
so you could say only the DB class can call the get_db_auth function in the above example or that it only returns a result for the db class and for other classes it would return a blank array.
site | / blog |
Code:
trait CONFIG{
private $db_login = 'mylogin';
private $db_pasw = 'mypasw';
public function get_db_auth(){
return array($db_login,$db_pasw);
}
}
class DB{
use CONFIG
public function connect(){
$db_auth = $this->get_db_auth();
$db = my_db_connect('localhost',$auth[0],$auth[1]);
return $db
}
}
$db_obj = new DB();
$db_con = $db_obj->connect();
And secondly, was wondering if there was a way to only let specific classes call specific functions in a trait.
so you could say only the DB class can call the get_db_auth function in the above example or that it only returns a result for the db class and for other classes it would return a blank array.
site | / blog |