only one of those is correctOren wrote:it is defined and available within the function too.
get_defined_vars doesn't return superglobals when...
Moderator: General Moderators
Errrrrrrrrrfeyd wrote:You're having a real hard time understanding the differences between defined and available, aren't you? PHP is doing magic behind the scenes to make the request for $_GET['var'] to work. That's why they're called superglobals. They're defined once, available everywhere.
Did I say something else? When did you hear me saying they are defined more than once?
You keep getting me wrong... I didn't say it is being defined (a second time) withing the function, what I was trying to say was: it's already defined inside the function.Jenk wrote:only one of those is correctOren wrote:it is defined and available within the function too.
Edit: I really don't know... Maybe it has something to do with my english
the function is called get_defined_vars. It does this:
This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called.
Superglobals are defined outside the scope of your function. The only reason that you can use them inside of a function is because php makes them available inside the function behind the scenes. It does not define them there. Therefor, it does not show up when get_defined_vars() is called.

This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called.
Superglobals are defined outside the scope of your function. The only reason that you can use them inside of a function is because php makes them available inside the function behind the scenes. It does not define them there. Therefor, it does not show up when get_defined_vars() is called.

Finally, now I get you and you get mefeyd wrote:The function retrieves variables that have been defined in the context it is called it. The superglobals were defined in the global context therefore do not list in a function.
I don't know whether it's my english or the manual, but this (from the manual):
This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called.
doesn't sound the same (to me at least) as this:
Edit: After a second thought, I believe it's the manual and not my english. What do you, the native english speakers, think?feyd wrote:The function retrieves variables that have been defined in the context it is called it. The superglobals were defined in the global context therefore do not list in a function.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Well that's the answer ... but I can't say it's a very good one. The word defined is used in the manual for constants, functions and classes. Then "defined" is used for variables when discssing scope and specifically for "Pre-defined" variables which includes the super-globals.feyd wrote:You're having a real hard time understanding the differences between defined and available, aren't you? PHP is doing magic behind the scenes to make the request for $_GET['var'] to work. That's why they're called superglobals. They're defined once, available everywhere.
It looks like the combination of a poor use of terms and a practical decision not to clutter up the array returned by get_defined_vars() with superglobals and probably internals naming cruft. I think a better term might have been "declared" when discussing variables.
Code: Select all
$glo = 1;
function check() {
global $glo;
global $_GET;
$loc = 2;
print_r(get_defined_vars());
}
check();(#10850)
That's interesting... It prints:arborint wrote:Code: Select all
$glo = 1; function check() { global $glo; global $_GET; $loc = 2; print_r(get_defined_vars()); } check();
Code: Select all
Array
(
[glo] => 1
[loc] => 2
)Yes, but it has never been defined within the function's scope, thefore it shouldn't be part of the result - which proves that either the definition of this function in the manual is wrong or the function itself has some problems and it doesn't work as it should.feyd wrote:The global keyword makes it defined. It's still the same situation as before with a superglobal though. PHP's just ignoring the request, because it's silly.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
If you truely feel that way then I suggest you go search the bug database. If there isn't a bug on it, make one.
http://bugs.php.net
http://bugs.php.net