external_plugin and globals

Creating and modifying plugins.
Post Reply
Posts: 20
Joined: Wed Jun 08, 2005 12:48 am

external_plugin and globals

Post by prim8 » Thu Jul 07, 2005 9:33 pm

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;

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 />";


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.

User avatar
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany

Re: external_plugin and globals

Post by garvinhicking » Fri Jul 08, 2005 10:27 am

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. :)

# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply