samedi 26 avril 2014

php, dynamically creating variables


Vote count:

0




(sorry for my bad English, i use Google.Translate) faced with the problem of dynamically creating variables in the class. There are classes at the entrance to __construct transferred to variables. further cycles



foreach ($collector as $key => $field) {
$this->$key = $field;
}


variables are added to the class. but this code works in other classes, except one. here is the class



foreach ($collector as $key => $field) {
$this->$key = $field;
if (isset($this->$key))
var_dump($this->$key);
}
var_dump('<pre>',$collector);
var_dump($this);
die();


var_dump('<pre>',$collector) - dumps the object



if (isset($this->$key))
var_dump($this->$key)


call magic __get(); since there is no variable


var_dump($this) - dumps the object but necessary variables I can not see.


Help me, please!



asked 59 secs ago






Aucun commentaire:

Enregistrer un commentaire