note 109067 added to language.variables.variable
| From: | mwwaygooAThotmailDOTcom | Date: | Mon, 18 Jun 2012 14:27:36 +0000 |
| Subject: | note 109067 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188669@lists.php.net to get a copy of this message | ||
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);
}
}
?>
----
Server IP: 92.48.119.85
Probable Submitter: 81.144.235.82
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/109067
Del: integrated -- https://master.php.net/note/delete/109067/integrated
Del: useless -- https://master.php.net/note/delete/109067/useless
Del: bad code -- https://master.php.net/note/delete/109067/bad+code
Del: spam -- https://master.php.net/note/delete/109067/spam
Del: non-english -- https://master.php.net/note/delete/109067/non-english
Del: in docs -- https://master.php.net/note/delete/109067/in+docs
Del: other reasons-- https://master.php.net/note/delete/109067
Reject -- https://master.php.net/note/reject/109067
Search -- https://master.php.net/manage/user-notes.php