473,725 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List predefined variables

Is there any way to tell PHP predefined variables ($GLOBALS, $argv,
$argc, $_GET, $_POST…) from *global* user-defined variables? Neither
$GLOBALS nor get_defined_var s() 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.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Oct 2 '08 #1
2 2695
On 2 Oct, 12:24, "Álvaro G. Vicario"
<alvaroNOSPAMTH A...@demogracia .comwrote:
Is there any way to tell PHP predefined variables ($GLOBALS, $argv,
$argc, $_GET, $_POST…) from *global* user-defined variables? Neither
$GLOBALS nor get_defined_var s() 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_supergl obal_globals()
{
$result=array() ;
foreach ($_GLOBALS as $anon_name =$anon_value) {
if (($anon_name!=' anon_name') && ($anon_name!='a non_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.
Oct 3 '08 #2
C. (http://symcbean.blogspot.com/) escribió:
>Is there any way to tell PHP predefined variables ($GLOBALS, $argv,
$argc, $_GET, $_POST…) from *global* user-defined variables? Neither
$GLOBALS nor get_defined_var s() put user data apart.
function get_non_supergl obal_globals()
{
$result=array() ;
foreach ($_GLOBALS as $anon_name =$anon_value) {
if (($anon_name!=' anon_name') && ($anon_name!='a non_value')) {
if ($_GLOBALS[$anon_name]===$$anon_name) {
// its a superglobal
} else {
// its a user global
$result[]=$anon_name;
}
}
}
}
I had tried this approach but it didn't work because superglobals cannot
be used with variable variables. However, I've found a workaround
with... ahem... eval():

<?php
foreach ($GLOBALS as $anon_name =$anon_value) {
if (($anon_name!=' anon_name') && ($anon_name!='a non_value')) {
$is_superglobal = eval('return isset($' . $anon_name . ');');
echo $anon_name . ': ' . ($is_supergloba l ? 'superglobal' : 'user') .
"\n";
}
}
?>

GLOBALS: superglobal
argv: user
argc: user
_POST: superglobal
_GET: superglobal
_COOKIE: superglobal
_FILES: superglobal
_SERVER: superglobal
my_variable: user
foo: user

Of course, I guess there's nothing I can do with predefined variables
that are not superglobals (e.g. argv & argc).
- 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.
Well, I need some predefined lists anyway ("if", "else", "new"...) so I
guess it won't be a great deal. It's easier than writing a Zend
extension ;-)

Thank you for your suggestion.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Oct 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1850
by: Klaus Neuner | last post by:
Hello, Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in dict = In order to avoid problems in the future, I tried to get the list of all those names, but I could not find it. (The Python Reference Manual
0
10209
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means "Specified partition does not exist". Does anybody know if it is a database problem or a problem of
9
1668
by: danny van elsen | last post by:
hello all, I have an application in which I build a list<node>, with potentially thousands of nodes. each node has an "index", and all nodes are ordered by this index. this index reflects a value that has been computed before, and will range from 0 to N. node 0: index 0
33
2858
by: abs | last post by:
Hi all. My list: <ul> <li id="a" onclick="show(this)">Aaaaaaaa</li> <li id="b" onclick="show(this)">Bbbbbbbb</li> <li id="c" onclick="show(this)">Cccccccc <ul> <li id="d" onclick="show(this)">111111</li>
25
5351
by: prabhat143 | last post by:
Hi, Given a singly linked, null terminated list, how can it be converted to tree? Each node in the list has three attributes: it's ID, it's parent ID and of course, the next node it's pointing to. The parent id of root of the tree is 0. The length of list is not known. What will be the optimal solution? Node* convertToTree(Node* listHead);
1
1403
by: Le Poisson | last post by:
My apologies if my question sounds childish. Please explain the following code to me. I found it at the beginning of a script. if (isset($_REQUEST) OR isset($_FILES)) { echo 'Request tainting attempted.'; exit; } Also, I'll be very grateful if someone can suggest me a good reference
5
12843
by: ampeloso | last post by:
Hello, I would like to allocte memory, but I want it to start at a predefined address. I have a program that writes data to ROM in an embedded device and I would like to state where it goes. Can this be done and how? Thanks Mike
3
5835
by: bkamrani | last post by:
Hello, Sorry guys for this newbie questions. But I wonder if there is a standard or build-in method to know the methods of a class? I'm not originally a progrommer and I have worked with python/qt in a basic level. Now I work a package which has many predefined classes which I'm going to resue by importing them. I would like to know more about each imported class, what methods exists and so on. Printing the object or type(object)...
3
6358
by: Mister Joe | last post by:
I've tried searching w/ google and on php.net and still can't find a complete list off all exceptions that are predefined. I need a null object exception and don't want to write one if one already exists. Does anyone know where a comprehensive list is? Thanks
0
8751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9108
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6010
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4781
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3218
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2155
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.