PHP global variable is not changing -


this question has answer here:

i have problem php , globals. in code:

  1. at page starts, result is: test 123.
  2. after click in: listbox1click result is: xxxxxxxx.
  3. 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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -