List predefined variables

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor al baño María:

Re: List predefined variables

On 2 Oct, 12:24, "=C1lvaro G. Vicario"
Quoted text here. Click to load it

Why not just iterate over $_GLOBALS, and for each entry, check if it
is in scope:

function get_non_superglobal_globals()
   foreach ($_GLOBALS as $anon_name => $anon_value) {
      if (($anon_name!=3D'anon_name') && ($anon_name!=3D'anon_value')) {
         if ($_GLOBALS[$anon_name]=3D=3D=3D$$anon_name) {
              // its a superglobal
         } else {
              // its a user global

- 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.


Site Timeline