Possible Duplicate:
Checking a session variable in a PHP class
public function __construct(){
$this->languages = get_option('test_trans');
$this->default_lang = $this->default_language();
$this->taxonomies = get_taxonomies(array(),'names');
add_action('init', array($this, 'webchanics_e_translations_session_master'), 1);
session_start();
$this->current_language = $_SESSION['language'];
}
function webchanics_e_translations_session_master(){
if(!$this->languages){
unset($_SESSION['language']);
}else{
$check_lang_by_session = $this->check_language($_SESSION['language']);
if(!$check_lang_by_session){
$_SESSION['language'] = $this->default_lang;
}
$check_lang_by_url = $this->check_language($_GET['lang']);
if($check_lang_by_url){
$_SESSION['language']=$_GET['lang'];
}
}
}
This code sets a session based on some conditions, and the calls the value stroed in this session. Outside the class, the new value of the session is available instantly, but inside the class the value of $this->current_language remains the old one until I refresh the page again. What’s the explanation of this? and how to make the value inside the class to change instantly?
You are doing an assignment by value, not by reference.
Do it with reference:
$this->current_language = &$_SESSION['language'];