note 109067 deleted from language.variables.variable by danbrown

From: Date: Mon, 18 Jun 2012 14:36:21 +0000
Subject: note 109067 deleted from language.variables.variable by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188670@lists.php.net to get a copy of this message
Note Submitter: mwwaygoo AT hotmail DOT com ---- On the topic of variable variables with arrays AGAIN. Following on from the example by dlorre at yahoo dot com To set a variable to a value, when that variable COULD BE an array and without using EVAL, which may be disabled on the server. <?php class sample { var $errors_occurred=false; var $errors=array(); function var_set($variable, $value) { // sets the internal variable to the specified value if(stristr("[", $variable)) { $parts=split('[', $variable, 2); $variable='{'.$parts[1].'}['.$parts[2]; } $this->$variable=$value; } function log_error($text) { $this->var_set('errors_occurred', true); $this->var_set('errors[]', $text); } } ?>

« previous php.notes (#188670) next »