Page 2 of 3

Posted: Tue Aug 15, 2006 3:39 pm
by Jenk
Oren wrote:it is defined and available within the function too.
only one of those is correct ;)

Posted: Tue Aug 15, 2006 4:19 pm
by Oren
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.
Errrrrrrrrr :evil: :evil: :evil: :evil:
Did I say something else? When did you hear me saying they are defined more than once?

Posted: Tue Aug 15, 2006 4:22 pm
by Oren
Jenk wrote:
Oren wrote:it is defined and available within the function too.
only one of those is correct ;)
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.

Edit: I really don't know... Maybe it has something to do with my english :P

Posted: Tue Aug 15, 2006 4:30 pm
by feyd
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'm amazed this thread has gone this far..

Posted: Tue Aug 15, 2006 4:41 pm
by Luke
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.

Image

Posted: Tue Aug 15, 2006 4:47 pm
by Oren
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.
Finally, now I get you and you get me :D
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:
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.
Edit: After a second thought, I believe it's the manual and not my english. What do you, the native english speakers, think?

Posted: Tue Aug 15, 2006 4:53 pm
by feyd
The manual is just fine for me... but I can read technical manuals with great ease.

Posted: Tue Aug 15, 2006 4:54 pm
by Christopher
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.
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.

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();

Posted: Tue Aug 15, 2006 5:00 pm
by feyd
arborint wrote:I think a better term might have been "declared" when discussing variables.
There's a distinction in programming languages between "declared" and "defined" however. I would probably prefer "instantiated." Although I can't expect most people to spell that one right. :D

Posted: Tue Aug 15, 2006 5:04 pm
by Oren
arborint wrote:

Code: Select all

$glo = 1;
function check() {
     global $glo;
     global $_GET;

     $loc = 2;
     print_r(get_defined_vars());
}
check();
That's interesting... It prints:

Code: Select all

Array
(
    [glo] => 1
    [loc] => 2
)
$glo was defined within the global scope and not within the function's scope.

Posted: Tue Aug 15, 2006 5:10 pm
by feyd
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.

Posted: Tue Aug 15, 2006 5:18 pm
by Oren
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.
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.

Posted: Tue Aug 15, 2006 5:24 pm
by feyd
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

Posted: Tue Aug 15, 2006 5:27 pm
by Oren
Well, before I do that, what do you think? Do you agree with me?

Posted: Tue Aug 15, 2006 5:29 pm
by feyd
The function works perfectly fine for my needs. .. not that I ever use it.