PDA

View Full Version : variable scope


Jakeman
06-05-2004, 08:46 PM
I have a problem. Take this code for example:


<?php

function glug() {
global $a;

//code here
}

function blah() {

$a = 1;

glug();

}

blah();

?>


$a is not making it into glug() and I don't know why. It's value is nothing within the glug() function.

filburt1
06-05-2004, 08:57 PM
$a is defined in the local scope of blah(). glug() is using the global scope (a variable not defined in a function or class). The only way to pass $a is as an argument to glug(), or to make it global in the first place (not preferable).

Jakeman
06-05-2004, 09:05 PM
ahhh

your kung fu is strong http://www.mscclan.com/forum/images/smilies/ninja.gif