PHP, after setting an array in a method, how can I get it from a different method in same class -


i have class, in class have method sets array. how can values of array , use them method in same class?

this class:

class homecontroller extends controller {     private $tmp = array();      public function setvalues(){          array_push($this->tmp,"blue","yellow");          print_r(array_values($this->tmp)); // works well, can see values.     }       public function getvalues(){         print_r(array_values($this->tmp)); // doesn't work - shows empty array.         // return $this->tmp doesn't work - shows empty array.     }  } 

how can values of array?

i not sure how controllers work in laravel. however, if similar other frameworks controller not singleton. new controller potentially created each request. means calling setvalues(); on 1 instance of class , getvalues(); on another.

i pretty sure can configure laravel treat controller singleton.

http://laravel.com/docs/5.0/container shows how can register controller singleton if need to.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -