php - How to access a variable defined out side into inside a class function -
my code
$var = md5(rand(1,6)); class session{ protected $git; public function __construct($config = array()) { //// code } public function _start_session() { //code again.. } }
i want use "$var
" value inside class functions globally.
please update me how this.
you use dependency injection. pass required variables constructor
$var = md5(rand(1,6)); $session = new session($var); $session->_start_session(); class session{ public function __construct($var, $config = array()) { $this->var = $var; } public function _start_session() { echo $this->var; //code again.. } }
Comments
Post a Comment