note 86475 added to function.get-defined-vars
| From: | donovan at example dot com | Date: | Tue, 21 Oct 2008 16:15:27 +0000 |
| Subject: | note 86475 added to function.get-defined-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145541@lists.php.net to get a copy of this message | ||
As a note, get_defined_vars() does not return a set of variable references (as I hoped). For
example:
<?php
// define a variable
$my_var = "foo";
// get our list of defined variables
$defined_vars = get_defined_vars();
// now try to change the value through the returned array
$defined_vars["my_var"] = "bar";
echo $my_var, "\n";
?>
will output "foo" (the original value). It'd be nice if get_defined_vars() had an
optional argument to make them references, but I imagine its a rather specialized request. You can
do it yourself (less conveniently) with something like:
<?php
$defined_vars = array();
$var_names = array_keys(get_defined_vars());
foreach ($var_names as $var_name)
{
$defined_vars[$var_name] =& $$var_name;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 208.101.181.19
----
Manual Page -- http://www.php.net/manual/en/function.get-defined-vars.php
Edit -- https://master.php.net/note/edit/86475
Del: integrated -- https://master.php.net/note/delete/86475/integrated
Del: useless -- https://master.php.net/note/delete/86475/useless
Del: bad code -- https://master.php.net/note/delete/86475/bad+code
Del: spam -- https://master.php.net/note/delete/86475/spam
Del: non-english -- https://master.php.net/note/delete/86475/non-english
Del: in docs -- https://master.php.net/note/delete/86475/in+docs
Del: other reasons-- https://master.php.net/note/delete/86475
Reject -- https://master.php.net/note/reject/86475
Search -- https://master.php.net/manage/user-notes.php