Posted: Tue Aug 15, 2006 3:39 pm
only one of those is correctOren wrote:it is defined and available within the function too.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
only one of those is correctOren wrote:it is defined and available within the function too.
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.
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.

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.
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.
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.
Code: Select all
$glo = 1;
function check() {
global $glo;
global $_GET;
$loc = 2;
print_r(get_defined_vars());
}
check();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.arborint wrote:I think a better term might have been "declared" when discussing variables.
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.