autoload - How to load variables only when needed in PHP -


i have class multiple public properties objects being used in different parts of system. problem need load of public properties in each place i'm using objects of class, because loading entire list of properties every time take forever.

is there way can use __autoload or similar function call functions load different variables @ time called?

e.g.

class bread {   public      $ingredients,     $price,     $color;    public function magicloading($var) {     switch($var) {       case "ingredients" : return loadingredients();       case "price"       : return loadprice();       case "color"       : return loadcolor();       default            : break;     }   }    public function loadingredients() {     $this->ingredients = ...   } }  foreach($bread->ingredients $ingredient) {   //do stuff here } 

in code,

  • rename function magicloading __get,
  • add return statement in 'load...' methods
  • check variables have not been initialized yet.

and works !


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -