Page 1 of 1

external_plugin and globals

Posted: Thu Jul 07, 2005 9:33 pm
by prim8
I'm having some strange behavior related to global variables, and I wonder if anyone can comment as to what is going on here, and what config setting causes this behavior. I define an external_plugin:

Code: Select all

case 'external_plugin':
                    include 'ext.php';
                    return true;
                    break;

Code: Select all

<?
$abc = "my test";
$GLOBALS['def'] = "strange";

function printme() {
    global $abc;
    global $def;

    echo "abc is: ".$abc."<br />";
    echo "def is: ".$def."<br />";
}

printme();
?>
When I call through /plugin/ URL I get:

Code: Select all

abc is:
def is: strange
When I load ext.php directly I get:

Code: Select all

abc is: my test
def is: strange
I thought it was related to register_globals=Off, but that does not seem to be the case.

Re: external_plugin and globals

Posted: Fri Jul 08, 2005 10:27 am
by garvinhicking
Your file "ext.php" is included inside the plugin's method "event_hook". That means all variables declared in ext.php are local because of that method scope.

You will need to declare the variables as global already in the plugin's event_hook method signature. The easier way for you would be to use $GLOBALS though. Makes less headache. :)

Regards,
Garvin