Re: List predefined variables



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



Relevant Pages

  • List predefined variables
    ... Is there any way to tell PHP predefined variables ($GLOBALS, $argv, ... I’m writing a class to generate PHP definition files for syntax highlighting with two features: ... You can choose whether to include user data or not. ... I’ve kind of automated this hard-coding but it still smells of lame workaround. ...
    (comp.lang.php)
  • Re: use of constants in an interpreter environment
    ... echo FOO; ... variables are limited by scope whereas constants have global (and not ... The term 'superglobal' indicates that a constant is automatically global--i.e., automatically available in every scope, without the use of either the global keyword or the $GLOBALS array. ... A variable can be global, PHP has some variable superglobals, but there is no way to make a normal user-defined variable a superglobal. ...
    (comp.lang.php)
  • Re: global variables
    ... There's no way to define superglobals though -- PHP defines a few on its ... I intentionally left out elaborating about the nature of the globals vs superglobals because use of global variables is somewaht discouraged. ... You CAN use the runkit extension to define variables as superglobals. ...
    (comp.lang.php)
  • Re: globals and super globals
    ... "John" wrote in message ... > using globals is? ... Being an old timer, I consider superglobals sacrilegious. ... The language actually discourages you from ...
    (comp.lang.php)
  • Re: global variables
    ... languages even have the keyword "local" to prohibit a variable from ... In PHP the global keyword basically pulls a variable from the global ... There's no way to define superglobals though -- PHP defines a few on its ... Although I steer away from globals (in my current project, ...
    (comp.lang.php)