oop - how can i set the value of a variable be accessed by any method in a PHP Class? -


i'm trying use 2 methods in class.

the class structure looks similar this

class test extends {     private $dir;      public function __construct()     {         parent::__construct();     }      private function check_theme()     {         // checking here         $this->dir = // outcome of checking     }      public function load_theme()     {         $this->check_theme();     }      public function load_file()     {         $this->dir . $path . $to . $file     } } 

ok now, works if run like

$test = new test();  $test->load_theme(); $test->load_file(); 

but have different method want access directly want method know value of $dir is.

so if used $test->load_file(); load file because value of $dir set $test->check_theme();

i hope question properly. suggest keep flag when value of $dir set.

here before using $dir value, test ensure value set. if not call $load_theme() calls check_theme() in same sequence showed in question.

class test extends {     private $dir;     private $file_loaded;      public function __construct()     {         parent::__construct();         $this->file_loaded = false;      }      private function check_theme()     {         // checking here         $this->dir = // outcome of checking     }      public function load_theme()     {         $this->check_theme();         $this->file_loaded = true;        }      public function load_file()     {         if (!$this->file_loaded)             $this->load_theme();                     $this->dir . $path . $to . $file     } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -