Re: List predefined variables
- From: "C. (http://symcbean.blogspot.com/)" <colin.mckinnon@xxxxxxxxx>
- Date: Fri, 3 Oct 2008 02:35:28 -0700 (PDT)
On 2 Oct, 12:24, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@xxxxxxxxxxxxxx> wrote:
Is there any way to tell PHP predefined variables ($GLOBALS, $argv,
$argc, $_GET, $_POST…) from *global* user-defined variables? Neither
$GLOBALS nor get_defined_vars() put user data apart.
I’m writing a class to generate PHP definition files for syntax
highlighting with two features:
1. It takes data from current install (e.g., you get function names from
loaded extensions).
2. You can choose whether to include user data or not.
It’s been very easy with functions and constants but I can’t figure out
how to deal with variables, rather than hard-coding the names of
predefined vars... I’ve kind of automated this hard-coding but it still
smells of lame workaround.
Why not just iterate over $_GLOBALS, and for each entry, check if it
is in scope:
function get_non_superglobal_globals()
{
$result=array();
foreach ($_GLOBALS as $anon_name => $anon_value) {
if (($anon_name!='anon_name') && ($anon_name!='anon_value')) {
if ($_GLOBALS[$anon_name]===$$anon_name) {
// its a superglobal
} else {
// its a user global
$result[]=$anon_name;
}
}
}
}
- this is bit of a hack too - I think there are circumstances where it
won't work. I'd go with a predefined list of superglobals.
C.
.
- Follow-Ups:
- Re: List predefined variables
- From: "Álvaro G. Vicario"
- Re: List predefined variables
- References:
- List predefined variables
- From: "Álvaro G. Vicario"
- List predefined variables
- Prev by Date: massive mails & timeout
- Next by Date: Re: Simple PHP script?
- Previous by thread: List predefined variables
- Next by thread: Re: List predefined variables
- Index(es):
Relevant Pages
|