PHP global variable is not changing -
this question has answer here:
- php pass variable next page 8 answers
i have problem php , globals. in code:
- at page starts, result is:
test 123
. - after click in: listbox1click result is:
xxxxxxxx
. - after click in: listbox2click result is:
test 123
wrong!
is there method can change global variable in way? it's need change inside "listbox1click" function , displays code in: "listbox2click" function.
<?php require_once("rpcl/rpcl.inc.php"); //includes use_unit("forms.inc.php"); use_unit("extctrls.inc.php"); use_unit("stdctrls.inc.php"); //class definition class page1 extends page { public $label8 = null; global $somevar; $somevar = "test 123"; $this->label8->caption = $somevar; function listbox1click($sender, $params) { global $somevar; $somevar = "xxxxxxxx"; $this->label8->caption = $somevar; } function listbox2click($sender, $params) { global $somevar; $this->label8->caption = $somevar; } } global $application; global $page1; //creates form $page1=new page1($application); //read resource file $page1->loadresource(__file__); //shows form $page1->show(); ?>
thanks help
your solution this:
<?php require_once("rpcl/rpcl.inc.php"); //includes use_unit("forms.inc.php"); use_unit("extctrls.inc.php"); use_unit("stdctrls.inc.php"); //class definition class page1 extends page { public $label8 = null; private $somevar; public function __construct($application) { parent::__construct($application); //load storage $this->somevar = $_session['somevar']; $this->label8->caption = $this->somevar; } public function __destruct() { //save storage $_session['somevar'] = $this->somevar; } public function listbox1click($sender, $params) { $this->somevar = "xxxxxxxx"; $this->label8->caption = $this->somevar; } public function listbox2click($sender, $params) { $this->label8->caption = $this->somevar; } } global $application; //creates form $page1=new page1($application); //read resource file $page1->loadresource(__file__); //shows form $page1->show(); ?>
Comments
Post a Comment